1

I have a PHP script involving exec() that will run fine from the command line but not in a web context. The script is simply this:

<?php exec('echo "wee" > /home/jason/wee.txt');

If I call this script wee.php and run php wee.php, it works fine and wee.txt gets written.

If I go to http://mysite.com/wee.php, the script pretends to run fine but wee.txt doesn't actually get written.

Any idea why this is happening?

4 Answers 4

3

The web server runs as a different user, and that user does not have permission to write to your home directory.

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

1 Comment

Is there any way to make this work? like giving permission temporarily
1

The other posters are correct to suggest the web server user doesn't have rights to write to your home directory. To see if they are right try modifying the code to write to /tmp/wee.txt. That should be world writable.

Another possibility is that php can be configured to disable calling exec(). See http://www.cyberciti.biz/faq/linux-unix-apache-lighttpd-phpini-disable-functions/

Comments

0

Your web server probably (correctly) doesn't have the appropriate permissions to write to a home directory.

Comments

0

Noticed you are writing to /home/jason. Note that apache will be the one running this command (i.e. www-data user if using Ubunut or Debian). Does the process have the correect rights to write to that folder?

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.