Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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] PHP Warning:  fopen(../index.htm): failed to open stream: Permission denied in /srv/www/ on line 228
[Sat Oct 22 17:50:44 2011] [error] [client] PHP Warning:  fputs() expects parameter 1 to be resource, boolean given in /srv/www/ on line 229
[Sat Oct 22 17:50:44 2011] [error] [client] PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /srv/www/ 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,

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer

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).

share|improve this answer

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: You could also have a look at (PDF file) - a bit old but good enough to get you started with securing PHP.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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