Thursday, 14 April 2011

Folder permissions for Apache

Took me a while to figure this one out. I was getting a 403 forbidden error when going to http://localhost/russ.

I had this in the /etc/apache2/sites-enabled/000-default file

Alias /russ/ "/home/russ/public_html"
    <Directory "/home/russ/public_html">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

And had given the following permissions

$ sudo chgrp -R www-data /home/russ/public_html 
$ sudo chown -R russ /home/russ/public_html
$ sudo chmod -R 775 /home/russ/public_html

The problem was that the Apache user (www-data) also needs access to the parent directories. So repeat the above for /home/russ and /home.

1 comment:

  1. Or a simpler version would be to run:

    sudo chgrp -R www-data . && sudo chown -R russ . && sudo chmod -R 775 .

    replace "russ" with your user name.

    This will change the permissions for all files in the current and sub directories.

    ReplyDelete