Running shell script with PHP in Apache
What is the best way to run a simple Bourne shell script from a PHP script in Apache?
I thought sudo would do the trick.
Contents of /etc/sudoers:
apache ALL = (<user>) NOPASSWD: /home/<user>/bin/test.sh
The shell script:
echo "This is a test."
The PHP code:
$r = exec("sudo /home/<user>/bin/test.sh", $arrayOutput, $exeStatus);
if($exeStatus == 1)
But I keep getting "Process Failed!". What am I missing?
I originally had nologin as apache user shell so I put /bin/sh.
I am not sure, but I have seen plenty of problems in these forums of people trying to run sudo scripts through PHP. Perhaps you can have a search and see if any of them have been resolved.
Perhaps it is also a permissions issue. Does apache have permission to access /home/<user>/bin/test.sh? Typically your home directory is chmod 700, so apache will not be able to access the script.
As an aside, it is probably better to rewrite whatever code is in this script into pure PHP if possible.
I gave apache user a shell because I thought it was necessary for sudo to work.
|All times are GMT -5. The time now is 09:25 AM.|