Remote shell exec not finishing running. Random how far it gets. Centos 7.

Hey Guys,

Can anyone shed some light on why Digital Oceans VPS servers don’t like finishing running ssh exec commands run from php?

It works fine on hosts other than digital ocean, also using centos 7. and I can get putty to run the commands, but not if I connect through a php function. I have been using phpseclib.

I have had to split my php functions up into little bits and run them one at a time. Some of them don’t ever finish. like when I try to install sentora. It seems random how far it gets into the installation.

The Code works fine:

$ssh = new Net_SSH2("$domain");
if (!$ssh->login($username, $password)) {
    exit('Login Failed');

echo $ssh->exec("wget");
echo $ssh->exec("chmod +x install");
echo $ssh->exec("./install -t Europe/Germany -d host.$domain -i $ip");
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This question was answered by @ryanpq:

That is odd. I haven’t used this particular library but I’ve done some significant scripting using Ruby’s ssh library to do similar things. To narrow this down I have a couple ideas

  1. Try changing
echo $ssh->exec("./install -t Europe/Germany -d host.$domain -i $ip");


echo $ssh->exec("./install -t Europe/Germany -d host.$domain -i $ip > /somedirectory/output.txt");

This should log the output of the command to the specified file allowing you to take a look and possibly see what happened.

If you are simply installing a control panel on newly created droplets it might be worth looking into user-data. This allows you to pass a shell script to your newly created droplet that is run immediately on the first boot. We have a collection of pre-built user-data scripts that might be helpful as a reference.

If going in this direction you could implement a system like the following:

Control server (with your php script) kicks off droplet creation via the API, passing a user-data block with the domain in it. You can gather the new droplet’s IP address from droplet meta-data via curl. You can include a line in your user-data script to have the new droplet use curl or another method to report back to your control script that provisioning is complete.

View the original comment