30th May, 2008

Running multiple web sites in apache in your user directory

A lot of Apache installs by default assume the website is running as www-data:www-data in /var/www.

I personally want to work on my websites in my editor of choice, which requires user read/write to the filesystem. You can't generally edit these files logged in as a different user. It's easier to move your websites to your user directory, to do this, you just need to do a couple of things...

Apache needs to run as your user. The following needs to be run as root, or sudo for Debian/Ubuntu distributions...

nano /etc/apache2/envvars

change the line

export APACHE_RUN_USER=www-data

to your name. For example:

export APACHE_RUN_USER=newmediascientist

Ok, next time you restart Apache

apache2ctl restart

You'll be running as your user.

Now, create a local directory in your user directory. I choose ~/Web.

mkdir ~/Web

Inside this directory, create a directory for the website. This way you can have multiple sites.

mkdir ~/Web/Site1

Create a /etc/apache2/sites-enabled/site1 configuration file. You need to remap the local directory to the home directory. For example:

 DocumentRoot /home/adam/Web/Site1

If you've just copied your website from somewhere else, you may need to change the ownership of the directory. (Run as sudo for Debian/Ubuntu)

chown -R YOURUSER:www-data

Where YOURUSER is your name.

After that, it should all work fine. If you're having trouble, check /var/log/apache2/error.log

 

The opinions expressed here are my own and not those of my employer.