James Gardner: Home > Blog > 2009 > Apache Permissions

Apache Permissions

Posted:2009-06-01 15:29
Tags:Web, Hosting

When setting up virtual hosts on Apache it is a very good idea to create a different user for each virtual host.

You can add a new user like this:

$ sudo adduser packyears

If you already have files the new user should own you can change their ownership like this:

$ sudo chown -R packyears /var/www/vhost/packyears/

The easiest way of setting up the appropriate permissions is to add the Apache user to the packyears group and then grant group read permission to everything Apache needs to read and group write permission to everything it needs to write to (if any).

$ sudo usermod -a -G packyears www-data
$ chmod -R g+r /var/www/vhosts/packyears/htdocs
$ chmod -R g+w /var/www/vhosts/packyears/data

As it happens, I prefer having files in /home/packyears to /var/www/vhosts/packyears so that all the user's files are in one place and so that I'm already in the right directory when I log in via SSH. You can set it up the virtual hosts however you like though.

(view source)

James Gardner: Home > Blog > 2009 > Apache Permissions