Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using a CentOS for serving PHP webpages.

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

/svr/www/website1.com
/svr/www/website2.com

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,

share|improve this question

3 Answers 3

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

share|improve this answer

Your Answer

 
discard

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.