Like most developers, I work locally. I develop on Windows (don’t judge) and run WAMP. In WAMP, websites are located in the C:\wamp\www directory. You can access a website at localhost/mysite. You all know this. The standard way of hosting sites in WAMP is restrictive. Setting up a virtual host (vhost) provides several benefits:

  • Virtual Hosts make URLs cleaner – localhost/mysite vs mysite.local.
  • Virtual Hosts make permissions easier – restrict access for a single vhost on a local network vs permitting access to all sites on your local network.
  • Some applications require a “.” in the URL (ahem Magento). While you can setup localhost.com/mysite by editing the Windows hosts file, creating a vhost is a better solution.

So, let’s setup a virtual host in WAMP.

  1. Include You Virtual Host Configuration File in Apache

    • Open your Apache configuration file located in C:\wamp\bin\Apache#.#.#\conf\httpd.conf, where #.#.# corresponds to the version of Apache that you are running in WAMP.

      Screenshot of the Apache configuration file in WAMP
      Apache Configuration File
    • Search for “LoadModule vhost_alias_module” (without the quotes) and uncomment the LoadModule vhost_alias_module modules/mod_vhost_alias.so directive below.

      Screenshot of the vhost_alias_module directive in the Apache  configuration
      Include Virtual Host Module
    • Search for “Virtual Hosts” (without the quotes) and uncomment the Include conf/extra/httpd-vhosts.conf directive below.

      Screenshot of the include virtual hosts directive in the Apache configuration file
      Include Virtual Host Configuration
    • Save and close the httpd.conf file.

  2. Update Your Virtual Host Configuration File

    • Open your Apache Virtual Hosts (vhost) configuration file located one directory down from the Apache configuration file directory in C:\wamp\bin\Apache#.#.#\conf\extra\httpd-vhosts.conf.

      Screenshot of the Apache virtual hosts configuration file in WAMP
      Apache Virtual Hosts
    • Add the configuration for your new vhost. While virtual host configuration is outside the scope of this article, I suggest you visit the Apache project’s documentation. It does a decent job of explaining the various configuration directives. I have included mine below with some comments as a starting point.

      Screenshot of a virtual host being added to Apache
      Add Virtual Host
    • Save and close the httpd-vhosts.conf file.

  3. Update Your Windows Hosts File

    • Open your Windows hosts file located in C:\Windows\System32\drivers\etc\hosts.

      Screenshot of the Windows hosts file
      Windows Hosts File
    • Add a new entry for the vhost you created in step 2.

      Screenshot of a new host being added to the Windows hosts file
      Add New Host
    • Save and close the hosts file.

    • Resart All Services in WAMP, pop open a web browser and access your new virtual host. Celebrate!

      Screenshot of the WAMP menu option to restart all services
      Restart All Services

      Screenshot of john-dugan.com running on the johndugan.local virtual host in WAMP
      johndugan.local Virtual Host
Posted by: John Dugan

Comments