getting php to run a bash script with the correct privileges

Dear all,

Please can you help me with a problem I’ve been trying to solve for the last couple of days. I can’t find a solution that works. I’m using php5, on an apache server, sat on Amazon Web Services.

I am trying to get a php script “callbash.php” (called via ajax with some data) from “index.php” to call a bash script “bashcript.sh”. The bash script makes a directory [within a subdirectory called “tmp”], copies some images in to it, and then modifies the images.

The call to the script $scriptcall works correctly when I call it from the command line

scriptcall

Within callbash.php I’m executing the script using
shell_exec( $scriptcall );

But it fails to produce the same results.

I’ve also tried shell_exec('sudo '.$scriptcall);

For testing purposes (only) I’ve opened up the security
chmod 777 index.php callbash.php bashcript.sh

and I’ve also set the directory that the scripts sit in, and the subdirectory “tmp” to 777.

I’ve tried changing the owner of the scripts, and directories to www, www-data, root,…

Nothing seems to work. Am I missing something obvious, perhaps a php setting?

Thanks in advance, and warm regards,

Ben.

Hi all,

thanks to all who took the time to read and think about this. It turns out my version of php 5.3 was running in safe mode.
I turned it off in php.ini and restarted apache, and now it works!

Cheers,

Ben.

Sponsor our Newsletter | Privacy Policy | Terms of Service