I have a very simple script that is to test if running a shell_exec (or backtick operator) basically works:
#!/usr/bin/php5
<?php
echo "This is a PHP script\n";
echo `ls -l /home/stoysnet/`;
Unless I run this as root, it always gives me:
$ ./foo.php
This is a PHP script
Warning: _shell_exec(): Permission Denied in /home/stoysnet/foo.php on line 5
I've tried running this via PHP in a few different ways, but I always get the same error. However, when I put the script into a subdirectory of /etc/
owned by root:root
and executed as root
it works.
What gives?
Update: Just to clarify:
- I am trying to run it as the
stoysnet
user via the command line. I am able to execute the command being passed toshell_exec
via the same session. - If I move the script to
/etc/somedir/
and execute is asroot
, it works as expected. - The script itself runs, just not the backtick operator or
shell_exec
part - Execution permissions are set, and
777
doesn't work either.