1

I am using the shell_exec command to send commands to my school unix server. I can do 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,

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.