Apache and user management in Ubuntu
I have Ubuntu 10.1 installed and I have setup Apache2.
I am going to host about 4-5 websites on this machine, so I need to have a user that controls files/permissions for each website.
I have added a user named 'site1' to control site1.com.
I know I should change the root folder in my apache config to be /home/site1 for site1.com
But the apache server runs on the www-data user, which will not be allowed to perform in actions on /home/site1.
How do I add permissions for www-data to the necessary folders?
Thanks,
Solution 1:
Here is how I would do it. Do the following as root (assuming the site1
user and home directory have already been created):
cd /home/site1
mkdir -m 0770 public_html
chown site1:www-data public_html
chmod g+s public_html
This creates the directory public_html
and makes it readable and writable by the www-data
group. This should allow Apache to have full access to it. Any files or directories created there will also be owned by the www-data
group, because the SGID bit is set on the directory.
Make /home/site1/public_html
the root directory of site1.com
in your Apache config. I feel it's better to put the web root in a subdirectory of /home/site1
, rather than in /home/site1
itself, to keep the site1
user's dotfiles and other potentially sensitive bric-a-brac out of there.