Reputation: 33
I am automating installing multiple WordPress blogs on a server. Basically, I need to run multiple wp-cli commands.
Using phpseclib and doing exec()
, doesn't work...
When I do something like:
$ssh->exec('wp core download');
I will just get:
/usr/bin/env: php: No such file or directory
Even though I can run it fine, in a normal ssh session...
If I try and $ssh->write
the command out and do '\n' it doesn't seem to do anything. Even if I just try to do a simple command like: touch foo.txt
Although that test "touch" command will work with exec...
The system is Ubuntu 14.04...
Any ideas?
I have to connect via SSH from PHP to do this for multiple domains on a server, as new customers come on.
Upvotes: 2
Views: 270
Reputation: 16802
The path to PHP probably needs to be defined. When you SH in with the regular SSH client it's probably running any number of Bash initialization files.
In light of this I have two thoughts.
Try to use a PTY. eg.
$ssh->enablePTY();
$ssh->exec('passwd');
echo $ssh->read();
Are you doing $ssh->read('[prompt]');
after doing the write("command\n")
? You may need to read the stream to get the command to actually be run.
Upvotes: 2