Apache2 - How to setup the directory permissions of website folder?

16,371

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:
16,371

Related videos on Youtube

André
Author by

André

Updated on September 18, 2022

Comments

  • André
    André over 1 year

    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,