Ubuntu – How to let Apache access /home/*/www/

apache-2.2Ubuntu

My apache server is currently running under user "www-data". However, this user doesn't have the permissions to access /home/username/www. What is the best way to give Apache the right permissions so that it can access all /home/*/www directories? Is there anyway to set a different user for Apache depending on which document root it is serving?

Best Answer

The typical way to do it is the change the group of those directories to www-data and allow executable access to the group:
chgrp www-data /home/*
chmod g+x /home/*
chgrp -R www-data /home/*/www
chmod -R g+x /home/*/www

This assumes that www-data is a pre-existing group (it usually is). If not replace www-data above with web and do the following first:
groupadd web
usermod -aG web www-data

Personally I'd do it with an ACL, but I don't know if setfacl is an option on Ubuntu:
setfacl -m user:www-data:r-x /home/*
setfacl -R -m user:www-data:rwx /home/*/www
setfacl -d -R -m user:www-data:rwx /home/*/www

Related Topic