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 w开发者_如何学Corks.
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.
Are you running this script as a different user than stoysnet
? What happens when you do run ls -l /home/stoysnet
as the same user that you're executing the PHP script as?
Seems like you need to run the script as a user who has permission to /home/stoysnet/
.
精彩评论