Oliver Nassar

Enabling an Apache Virtual Host with Sites Available/Enabled Directory

July 19, 2012

I keep forgetting, so I'm sure this will help me later, and maybe be useful to others.

If you use the sites-available and sites-enabled directories in Apache's /etc/apache2/ directory, here's how to get the files properly booted in.

Go to the /etc/apache2/sites-available directory and create a new file.
For example, a file named example.com with the contents:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/trunk
</VirtualHost>

Then change directories to /etc/apache2/sites-enabled. sites-enabled manages which of your virtual hosts will actually be booted into Apache when it starts up (opposed to simply exist for organizational reasons). This can be useful when you want to maintain virtual-host configuration files, but don't want the sites to be live, or are in a deployment process (or something).

Now that you're in /etc/apache2/sites-enabled, link your newly created file:

ln -s ../sites-available/example.com example.com

Boom.
Restart Apache (using sudo /etc/init.d/apache2 restart), and it'll get booted in.

This is pretty handy to keep multiple-sites organized.
Note that I didn't need to sudo the ln command. This is due to my default user (not root) having the required permissions. Depending on your own permissions, you may need to use sudo on it.