Linux – Correct user / permissions for running php script which writes to disk

linuxpermissionsPHPredhat

I've got a website at

/var/www/html

Which has a couple of files, one of which is:

-rwxr-xr-x  1 root root      1609 Feb 16  2010 send_form_email.php

(earlier it was 644)

I can access the file fine from the web, but with the error in apache:

PHP Warning:
file_put_contents(contacts.txt) [function.file-put-contents]:
failed to open stream: Permission
denied in
/var/www/html/send_form_email.php on
line 47, referer:
http://www.mysite.com/

What should I be changing? The file ownership? Contacts.txt?

Best Answer

If contacts.txt exists, then the permissions on contacts.txt needs to be changed, probably to 666. If it doesn't, then the permissions on the directory you want it to be in needs to be changed to allow the webserver to write to it.

The first way is the way you want to do it, especially if there's anything else in the directory you don't want to let web users write over.

Related Topic