johngirvin.com

John Girvin

This is the blog of John Girvin, a software engineer and web developer based in Belfast, Northern Ireland. He draws on over 14 years of hard won, real world experience of different projects, clients and working environments. Visit the rest of the site to find out more and get in touch.

John is currently working with the Art Technology Group (ATG), developing J2EE based, market leading e-commerce technology.

multiple websites on one pc with apache virtual hosts

April 22nd, 2009 by John Girvin

Craig Buckler at Sitepoint described one method of using the hosts file on your PC and Apache’s NameVirtualHosts feature to ease complexity of working with more than one Apache HTTPD locally hosted web project. The method he describes is very usable, but it adds an external dependency for your projects and it’s not the way I’ve been working.

Since I tend to work only on one site at a time, I have developed scripts to start up the correct versions of Apache, PHP, MySQL etc. that each project requires (depending on where it will eventually be hosted) and pull in the correct configuration for each of those components.

Each project has its own Apache configuration file which reads in a master Apache configuration using the Include directive, before applying project specific changes.

In the development environment for this site, johngirvin.com, I have the following Apache configuration:

# master configuration
Include c:/foo/_conf/apache-2.2.08.conf
Include c:/foo/_conf/php-5.2.6/apache.conf
 
# project specific configuration
Listen 80
DocumentRoot c:/foo/johngirvin.com/trunk/httpdocs/
...

In the past I’ve also used one configuration file with different Listen ports for each virtual host, which avoids making any changes to the hosts file and has minimal project specific configuration, but gets unwieldy as the number of hosted sites grows and you have to remember which site lives on which port.

I’ve since found it easier to use the above “layered modular configuration” approach. Furthermore, it permits using different versions of Apache, PHP and MySQL – or even alternatives such as Ruby, Python, PostgreSQL etc. – for different projects on one workstation.

The best solution, as ever, depends on your needs.

John Girvin
Bookmark and Share

John Girvin is an experienced a software engineer and web developer based in Belfast, Northern Ireland. He draws on over 14 years of hard won, real world experience of different projects, clients and working environments.

John is currently working with the Art Technology Group (ATG), developing J2EE based, market leading e-commerce technology.

If you liked this article, why not subscribe to the RSS feed for more?

one comment on “multiple websites on one pc with apache virtual hosts”

April 22 2009, 6:17 pm

This is similar to how the version of Apache2 shipped with Debian works: a separate configuration for each virtual host.

`sudo apache2ctl -S` on *nix will tell you which ports & names are being listened for & the corresponding document roots. Dunno what the equivalent on Windows is though…

Quite often I’ll add entries into my hosts file and use named virtual hosts instead of having httpd listening on a huge number of ports.

share your thoughts?

design & content © 2008-2010 john girvin, all rights reserved.