Saturday, July 05, 2008

Multiple apache sites on localhost

I do all my application development locally, but for a while haven't needed to have two instances of locally running applications. In the past, I had setup apache to serve multiple local instances, but I hadn't written down the process.

First of all, alter /etc/hosts to add a line for your new site. localhost.localdomain localhost<br /> localccc.localdomain localccc
Then, alter the apache config: create a file per site in /etc/apache2/sites-available:
<VirtualHost localhost>

ServerName localhost
ServerAdmin webmaster@localhost
ServerSignature On

DocumentRoot /home/elements/htdocs/

Options FollowSymLinks
AllowOverride None

<Directory home/elements/htdocs/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all

ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
LogLevel warn

Also remove the contents of default: just empty it.
Then enable the sites you've created (run it once for each filename you've created):
a2ensite localhost
Finally, restart the server
And, as Gordon Ramsay would say... DONE.

No comments: