This article describes how I proceeded to host multi-sites under Apache and Wamp Server on my computer.
When I decided to develop several sites, I thought that would be helpful to have a copy of each site running on my local computer. With Apache it is fairly easy to configure multiple sites under one install. This article outlines the basic steps for configuring Apache's "Named Virtual Hosts" feature under WAMP Server on Windows Vista.
Configuring Windows and Apache are two different but related processes. Two files are involved:
- hosts - in Windows and other operating systems, this file is used to associate host names with IP addresses. It contains the mappings of IP addresses to host names.
- httpd.conf - it is the main configuration file for the Apache web server.
and they both have to be modified.
The hosts file
This file is located in the directory C:\Windows\System32\drivers\etc folder on my computer. In Windows and other operating systems, this file is used to associate host names with IP addresses. It contains the mappings of IP addresses to host names.
It is necessary to tell Windows of our purpose: direct the new Web sites to the host.
The httpd.conf file
This file is located in the directory C:\wamp\bin\apache\Apache2.2.11\conf folder on my computer. It is the main configuration file for the Apache web server. The article entitled Name-based Virtual Host Support on the Apache Web Site is a very good guide to this process.
Modifications to the hosts and httpd.conf files
In the host file
In Windows, this file is the local DNS server. It already contained the statement "127.0.0.1 localhost" and I added the two addresses highlighted in yellow: "gtro" and "tripod". That is all that was needed for this file.
In the httpd.conf file
Modifying the httpd.conf file was somewhat more complex. Having to choose between IP-based and name-based virtual hosting, I decided for the former as it is much simpler to implement and allow all virtual sites to share the same IP address.
To use name-based virtual hosting, I had to designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHost directive. In the normal case where any and all IP addresses on the server should be used, you can use * as the argument to NameVirtualHost. Though I was not planning to use multiple ports (e.g. running SSL) I added a Port to the argument[*:80].
The next step was to create a <VirtualHost> block for each of the hosts that are to be served (including localhost which was already served). I used "*:80", the argument of the NameVirtualHost directive as the argument of the <VirtualHost> block. The ServerName and the DocumentRoot directives are as shown below:
NameVirtualHost *:80 <VirtualHost *:80> ServerName localhost DocumentRoot "c:/wamp/www/" </VirtualHost> <VirtualHost *:80> ServerName gtro DocumentRoot "C:/Users/Georges/Documents/Mes sites Web/www" </VirtualHost> <VirtualHost *:80> ServerName tripod DocumentRoot "C:/Users/Georges/Documents/Mes sites Web/tripod" </VirtualHost>
With only these modifications made to httpd.conf, I restarted the server and found out that, on loading either the "gtro" or the "tripod" host, I was getting the following message "Forbidden - You don't have permission to access / on this server." from the browser instead of the content of the page. Something else had to be configured.
Since the DocumentRoot directories specified were outside of the DocumentRoot specified by "localhost", I had to include <Directory> blocks as follows:
<Directory "C:/Users/Georges/Documents/Mes Sites Web/www"> Options Indexes FollowSymLinks allow from all order allow,deny # Enables .htaccess files for this site AllowOverride All </Directory> <Directory "C:/Users/Georges/Documents/Mes Sites Web/tripod"> Options Indexes FollowSymLinks allow from all order allow,deny # Enables .htaccess files for this site AllowOverride All </Directory>
With the addition of these blocks, access to all hosts was successful.
I was surprised to find out how easy it was to add hosts to the Apache server under Wamp. I hope that this description of the process may be useful to someone.