I am trying to ultimately use php\'s shell_exec
function to create new Linux users. I am, however, running into problems even with the debugging. Here is my code
shell_exec()
As a general case, rather than having PHP execute several commands sequentially, I write a shell script that does everything I need, then call it from PHP. There's one fewer link in the chain when debugging, and I find I a lot easier.
With regards to your SSH command itself, since apache is executing as www-data
, how is it logging into the machine in question as root? Have you added the apache user's key to the remote machine.
Please use my function found here.
Run the following code and tell us its output:
echo '<pre>';
print_r(execute('pwd'));
print_r(execute('touch test.txt'));
Edit: If you want to make my script more OO oriented:
function execute_o($cmd,$in){
$out=execute($cmd,$in);
if($out['return']!=0)
throw new Exception('Error '.$out['return'].': '.$out['stderr'].'.');
}