Command Line PHP with shell_exec works for root but not others
- by Kristopher Ives
I have a very simple script that is to test if running a shell_exec (or backtick operator) basically works:
#!/usr/bin/php5-cli
<?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?