14
7
I'm trying to exec a .sh script from PHP, however it is not executing.
I checked the error logs, and I'm getting the 'sh: Permission denied' error. I checked under which user php is being run, and it's done under the apache user.
I tried changing the .sh's ownership to the apache user, but there is no result.
I thought at first this was because the script was outside the www/ dir, however even when I put the script in the same directory, the error is still being given.
Are there any solutions to this other than adding the apache user to the SUDOers list?
The sh script runs fine if I launch it from putty using the 'php filename.php' command.
3Is it a shell script or a PHP file? Your last paragraph isn't clear about that. Also, did you set execute permissions (
x
) on the file? Did you specify the script interpreter in a shebang line? – Daniel Beck – 2012-07-31T18:14:16.907It's a bash script to be ran from PHP. Yes I did make it an executable and I did specify the script interpreter. It works correctly when I execute the PHP script from putty and the bash script gets called and runs correctly. But if I run the php script from the webbrowser instead it fails to run the bash script and it will do this error since it's running as the apache user and not the user I use in putty. – Robin Presto – 2012-07-31T19:54:17.837
1Try
chmod 775 yourscript.sh
. That will giver-x
(read and execute) permissions to "Other" users on that file. – Rhyuk – 2012-07-31T20:00:16.983I tried it. No luck.. I can't know the exact reason until tomorrow though. I don't have access to the logs from my location. I will get back to you guys. Thank you for your help. :) – Robin Presto – 2012-07-31T20:19:30.750