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.
127.0.0.1 localhost.localdomain localhost<br />127.0.0.2 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/

<Directory>
Options FollowSymLinks
AllowOverride None
</Directory>

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

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

</VirtualHost>
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
/etc/init.d/apache
And, as Gordon Ramsay would say... DONE.

No comments: