maetl

Running multiple virtual hosts under Apache on Windows XP

Notes

This will be of no interest to most people but it's useful to note for future reference. The various click-installer solutions to set up Apache and PHP under Windows such as WAMP don't seem to automate the setup of virtual hosts, but it's fairly straightforward to do manually:

  1. Create the local directory structure for the new application somewhere useful, eg: C:Documents and SettingsUserMy DocumentsProject Name
  2. Add the new hostname in the Windows hosts file C:WINDOWSsystem32driversetchosts, eg:
    127.0.0.1 localhost
    127.0.0.1 project-name
    
  3. Edit the httpd.conf file to include the virtualhost definitions at startup (The default WAMP install requires uncommenting this line and linking it to the correct file path), eg:
    # Virtual hosts
    Include "c:/wamp/apache2/conf/extra/httpd-vhosts.conf"
  4. In the httpd-vhosts.conf file, specify the mapping from the project folder to the new hostname:
    NameVirtualHost *
    
    # this is the default mapping to http://localhost/
    
        DocumentRoot C:wampwww
        ServerName localhost
    
    
    # the new virtual host mapping to http://project-name/
    
        DocumentRoot "C:Documents and SettingsUserMy DocumentsProject Name"
        ServerName project-name
      
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
        DirectoryIndex index.php
      
    
    		
    
  5. Restart Apache and go...