HOWTO: Apache Virtual Hosts
Following a read of an old Mezzoblue article, I decided it was time to have a similar setup on my Gentoo box. Here’s how I did it.
Installing Apache
I won’t go into this as each distribution of linux is different. I will say that I used the most recent stable release (2.0.54-r8) of apache2 in Gentoo’s portage.
Setting up the configuration files
Apache.conf (/etc/apache2/conf/apache.conf)
Not much needed here. I simply uncommented (removed the #) the following line.
Include conf/vhosts/vhosts.conf
This allows me to setup all of my virtual hosts in a separate file that should be saved in future upgrades.
vhosts.conf (/etc/apache2/conf/vhosts/vhosts.conf)
This is where you setup your virtual hosts. The Mezzoblue article touches upon this, but I’ll post my file for you to take a look at. You need one for each site you plan on hosting.
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName www.jeffreyfetting.dev
DocumentRoot /home/jfetting/WWW/jeffreyfetting
</VirtualHost>
hosts (/etc/hosts)
You must setup host redirection in this file. I simply one entry for each domain i wanted to setup.
127.0.0.1 www.jeffreyfetting.dev
Results
This setup allows me to type www.jeffreyfetting.dev into any of my web browsers and connect to a local development version of the site. This drastically improves the speed of development. Not to mention, I can’t screw up the live site while tinkering with the things. Plus, I always have a backup copy of the site’s design. It was well worth the time, which is only a couple of minutes.