My case is similar to PHP shell_exec running a shellscript with ssh but not the same.
Situation: I exchanged ssh-keys between the 2 servers, switched to the www-data
user and connecting to the 2nd server via SSH works without password.
Test 1: ssh [email protected] Documents/run.sh list works fine when executed in shell
Test 2: Putting a simple PHP Exec in a PHP file works fine. It returns an Array and the Retval is 0
Test 3: Putting the exec into a "big" PHP script and calling it will result in Retval 255 (Fatal Error ?!?!?)
So at the moment I don't really understand why it isn't working. I tried to figure out more details about the retval 255 but didn't get far.
The difference must be somewhere in PHP5 vs PHP5 cli. But before I had to use OpenVPN it worked fine also via normal Apache call.
2>&1
, e.g.$retval = shell_exec("/path/to/ssh ... 2>&1");
, so that you can inspect$retval
. That might show you some easy fix. Otherwise I'll try with a 'diagnostic' answer. – lserni Oct 22 '12 at 8:42