I decided last Saturday that I also wanted added to Subversion the part I change the most in the configuration file of both versions of Apache HTTP server I use. Subversion is a version control system that I installed a few weeks ago.
I have two versions of Apache, an 1.3.x version that also supports PHP, and a 2.x version. Since I have several virtual hosts in use, a few for personal use, and a lot for my customers, maintaining two Apache server configuration files became cumbersome.
See Installing and configuring Apache on Windows XP for a much more complete step-by-step guide on name-based virtual hosting.
First I created a new subversion repository for the configuration I had in mind. I used a small Perl program I wrote a few days earlier which does the creating of directories, subdirectories, checking in, and checking out the trunk. After that, I renamed the httpd.conf file, and copied the httpd.default.conf as httpd.conf to have a pristine version back again. At the end of this file I added Include directives as follows:
Include "C:/ ... /The Castle/Configuration/Apache/server.txt" Include "C:/ ... /The Castle/Configuration/Apache/apache-1.3.31.txt" Include "C:/ ... /The Castle/Configuration/Apache/virtual-hosts.txt"
Note that I replaced a part of the path in the above snippet with ... in order to keep each line short. In the actual file each directive uses a full and correct path.
The virtual hosts file is shared between both versions of Apache and looks as follows:
NameVirtualHost *:80 <VirtualHost *:80> ServerName local.johnbokma DocumentRoot "C:/ ... /Projects/johnbokma/tmp" Alias /mexit/ "C:/ ... /Projects/johnbokma/site/web/mexit/" </VirtualHost> <VirtualHost *:80> ServerName local.castleamber DocumentRoot "C:/ ... /Projects/castleamber/www-new" </VirtualHost>
Note, again a part of each path has been replaced with ... in order to keep each line short.
In the first virtual host section I use an alias to create "mexit" under the document root as a kind of virtual sub directory. Note the / at the end of both the Alias and the path. The actual directory is not even a subdirectory of /johnbokma/tmp. This trick even works over a network (shared directory, tested). Subdirectories (versus Subdomains) have been discussed at great length, in quite a heated discussion between Bill Logan and me, on the Usenet group alt.www.webmaster around the end of May 2004, .
Each ServerName must be added to the hosts file (or DNS). Since I use Windows XP I edit the following file:
C:\WINDOWS\system32\drivers\etc\hosts which has (amongst others) the following entries:
127.0.0.1 local.castleamber 127.0.0.1 local.johnbokma
Using local as a prefix has an advantage if your browser shows locations that match when you type. As
soon as I have typed
local Firefox shows all available local URLs.
Thanks to how Subversion works, I can now keep track of changes to the virtual hosts file. The client I use, TortoiseSVN, uses overlays to show clearly when a file has been updated but not committed to the repository. Also, because I use the Include directive of Apache, I can share this file between different versions of the Apache HTTP server.
In the above screen dump TortoiseSVN clearly shows that the virtual hosts file has been updated but not committed to the repository yet.