Pavel Dubinin
Pavel Dubinin

Reputation: 2430

Apache+PHP write permissions on unix

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.

Upvotes: 5

Views: 13318

Answers (4)

symcbean
symcbean

Reputation: 48357

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.

Upvotes: 4

hurikhan77
hurikhan77

Reputation: 5931

I'd recommend switching apache to mod_itk as mpm and running the particular vhost with permissions of the owner document root directory and contained php scripts.

Upvotes: 0

Qwerty
Qwerty

Reputation: 1742

ls -la /var/www/public

Just to check :-)

Upvotes: 0

Amad
Amad

Reputation: 31

make chmod 775 to newtest.php ;)

Upvotes: 0

Related Questions