I'm using a CentOS for serving PHP webpages.

I have various websites inside "/svr/www"... My problem is that I created folders like:


And this folders have as owner "root" user, and I noticed that apache can't create new files inside this folders.

I have this errors in apache error.log:

[Sat Oct 22 17:50:44 2011] [error] [client xx.xxx.xxx.xxx] PHP Warning:  fopen(../index.htm): failed to open stream: Permission denied in /srv/www/site1.com/public/gne/gnerate.php on line 228
[Sat Oct 22 17:50:44 2011] [error] [client xx.xxx.xxx.xxx] PHP Warning:  fputs() expects parameter 1 to be resource, boolean given in /srv/www/site1.com/public/gne/gnerate.php on line 229
[Sat Oct 22 17:50:44 2011] [error] [client xx.xxx.xxx.xxx] PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /srv/www/site1.com/public/gne/gnerate.php on line 230

My question is... What is the correct way to setup permissions in folders that apache need to read, write and execute?

Some clue on this?

Best Regards,


Generally, your Apache server should have access to read anything that i supposed to be served and the write permissions should be strictly limited to files and folders, that the web application requires to function. You should never have world writable files (e.g. 777).

You could set it up so your own user owns the files but the apache group has the group ownership.

And then give yourself the permissions you need via the user and strictly limit the web server by setting group permissions.


1) Check under which user Apache is running by typing

 ps -ef | grep httpd

2) Change permissions on the folder where you want apache to be able to write (just those folders just to be more "secure") 3) Everything else could have any user/permission you like, important thing is that apache user will be able to read on those directories (so they should be at least 755 for the folders and 644 for the files).


Apache and php run as the apache user. In order to give Apache (and PHP) read-write permissions, you should first change the owner of the files with chown -R apache: /srv/www/*.

You should also make sure you secure your PHP installation. Here's a quick and comprehensive guide here: http://www.jamescun.com/2011/10/securing-php/. You could also have a look at http://www.phpgenious.com/test/phpsecurity.pdf (PDF file) - a bit old but good enough to get you started with securing PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.