Assuming, that command in /opt/local/bin, change the command to
$cmd ='export PATH=$PATH:/opt/local/bin; myCommand 2>&1';
echo exec($cmd,$out);
To debug PHP exec command, Read this
For example:
For the PHP code:
$cmd = "gmake";
echo exec($cmd,$out);
There will be no output. In your web server error log, your will have :
sh: gmake: command not found
To fix this, we need to export the PATH of the gmake.Go to your terminal, find where your command is located, In this example:
$ which gmake
/opt/local/bin/gmake
So, modify you PHP code as following:
$cmd ='export PATH=$PATH:/opt/local/bin; gmake 2>&1';
echo exec($cmd,$out) ;
This will output, on your web page
gmake: *** No targets specified and no makefile found. Stop.
sh: /export: not found
ReplyDelete:( any idea?
Hi Juan,
ReplyDeleteCan u tell me the command string your trying to execute
This comment has been removed by the author.
ReplyDeleteHi Juan,
ReplyDeleteI want to execute sh file in php. Below is my code .
<?php
$output = shell_exec("sh /home/abc.sh");
echo "<pre>$output</pre>";
?>
when i run on browser i am not getting any out put.
So plz help me
Can you by appending 2>&1 to the command...
Deleteecho shell_exec("sh /home/abc.sh 2>&1");
can you give meyour fb id please ?
ReplyDelete