I am using the shell_exec command to send commands to my school unix server. I can do开发者_JAVA技巧 things like ls echo and things like that but anything that has to do with creating or deleting a file does not work. I figured I can just create a script for the command I want to perform and run the script with shell_exec, however this is a very tedious process is there any other way around this issue??
Thanks,
shell_exec()
is a very bad way of executing commands just because leaving it open, you're leaving your server a whole lot more vulnerable if someone exploits your PHP code, or manages to upload a PHP file. Instead, if you can, you should use PHP functions like mkdir()
and fopen($file, '(r|a|w)+)
so your file is created if it doesn't exist. In fact, leaving shell_exec()
, exec()
, pass_thru()
and the like in your code, any exploits can execute shell commands on your server.
Now, in relation to the original question, have you checked permissions on the files and directories you're attempting to work with? The user running your PHP needs to have permission to work with the files and directories you're attempting to access. If you're unsure, just chmod 777
any of your files and directories that you need to use in PHP.
Sounds like a permissions problem. Run whoami
from within PHP and see what user it's running as. If your school is also using something like SELinux, then there's additional restrictions on process beyond just those set by user/group/mode. But that's a starting point.
精彩评论