Setting Up Virtual Servers in WAMP

One tool I find indespensible in my job is virtual servers with WAMP. Virtual Servers allow you to run multiple projects at the same time on your localhost allowing you to quickly and easily change projects. Setting up Virtual Servers is easy:

  1. Edit httpd.conf

    This file is found in C:\wamp\bin\apache\Apache2.2.11\conf. Uncomment this line will include the apache virtual hosts setup file.

    Include conf/extra/httpd-vhosts.conf

    Search for <Directory /> in the httpd.conf file. The “default” settings here are really restricted so for a local dev setup you can change them to:


    <Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Allow from all
    </Directory>

    Security note: now doing this will open up your local server to be seen by everyone. This means that everyone in you office can ping your machine (good for testing). This also means if you’re a one man show or contract plugged directly into your modem (do people still do this) you’re opening your localhost via port 80 to the world.

  2. Edit httpd-vhosts.conf

    This file is found in C:\wamp\bin\apache\Apache2.2.11\conf\extra. Remove the example <VirtualHost> entries and add the following for each project.

    <VirtualHost *:80>
        DocumentRoot "C:\ProjectPath\"
        ServerName ProjectName
        ErrorLog "logs/ProjectName-error.log"
        CustomLog "logs/ProjectName-access.log" common
    </VirtualHost>

    In the above example DocumentRoot is the path to the root of your project, usually where the index file is. ServerName is what you’ll type in your browser to access the project. If you set this to “myProject” you’d access in the browser by visiting http://myProject. ErrorLog & CustomLog are the error logs for each project, if you don’t include these lines all errors will be logged to the regular localhost error logs. I don’t use these often but keep them just in case.

  3. Edit hosts

    Your hosts file is found in C:\WINDOWS\system32\drivers\etc. For each project you added in step 2 add the following entry in to the hosts file where ProjectName is the same as the ServerName variable you set in the httpd-vhosts.conf file. This tells the browsers on your system to pass all calls from http://ProjectName to your localhost.

    127.0.0.1    ProjectName

  4. All Done

    Make sure all your files are saved, restart WAMP and test. That’s it! When ever you want to add another project just start at step 2. Once you get used to the process you’ll be setting up a new project on your local dev environment in less than a minute.


WAMP/MAMP, Web Development