Php – Apache+PHP write permissions on unix

apachefile-permissionsPHP

I'm trying to launch PHP site with apache on fedora and I have a problem about writting permissions. It looks like apache does not have write permissions to some folders, but I canno understand why.

I've checked httpd.conf and it has group: apache, user: apache.
I then made:
chown -R apache:apache www and set 777 permissions to the folders, but it still says:

Warning: file_put_contents(/var/www/public/temp.txt) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/public/newtest.php on line 8

Please advice.

UPDATE:
Btw, if I make "php newtest.php" from command line, the file temp.txt is created with group root and user root. It just doest not work from the browser.

Best Answer

Warning: file_put_contents(/var/www/public/temp.txt) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/public/newtest.php on line 8

There is so much bad stuff here.

Lets start with the fact that you really want to keep httpd writeable files well away from your code - certainly in a seperate directory, preferably outside the document root altogether.

chown -R apache:apache www and set 777 permissions to the folders

And did you check afterwards what the permissions actually were? BTW see also the point above - if you've made your entire website writeable by the everybody then you're just asking for trouble. You certainly chouldn't change BOTH the owner AND the permissions.

Have you got SELinux enabled? (run sestatus as root). If so then you either need to disable it or learn how to configure it - but I'd recommend you get to grips with old-fashioned permissions first, then disable SELinux.

C.