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 http://sentora.org/install");
echo $ssh->exec("chmod +x install");
echo $ssh->exec("./install -t Europe/Germany -d host.$domain -i $ip");
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!
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
- Try changing
echo $ssh->exec("./install -t Europe/Germany -d host.$domain -i $ip");to
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.