Setup a Virtual Host on WAMP in 3 Easy Steps

Image for Wamp Serevr Local Virtualhost

Like most developers, I love to work locally and develop on Windows (don’t judge) using WAMP. In WAMP, websites are located in the C:\wamp\www directory (depends where you have installed wamp, mostly its C:). 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 on WAMP.

Step 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.

Image showing Wamp Apache httpd-conf Location

  • Search for “LoadModule vhost_alias_module” (without the quotes) and uncomment the LoadModule vhost_alias_module modules/mod_vhost_alias.so directive below.

Image showing Wamp Apache httpd-conf include-vhosts Position

  • Search for “Virtual Hosts” (without the quotes) and uncomment the Include conf/extra/httpd-vhosts.conf directive below.

Image showing Wamp Apache httpd-conf include-vhosts Position

  • Save and close the httpd.conf file.


Step 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.

Image showing Wamp Apache httpd-vhosts-conf Location

  • 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.

Image showing Wamp Apache httpd-vhosts-conf Site Configuration

  • Save and close the httpd-vhosts.conf file.

Step 3: Update Your Windows Hosts File

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

Image showing Windows Hosts File

  • Add a new entry for the vhost you created in step 2.

Image showing Windows Hosts Site Configuration

  • Save and close the hosts file.
  • Restart All Services in WAMP, pop open a web browser and access your new virtual host. Time to Celebrate Now!

Image showing Wamp Restart All Services

  • Open the site you configured in any browser on your machine to enjoy the work

Image of Localsite Access after Virtualhost Config


About author

Love coding, crazy about logic, like solution architecting and solving problems. Thirsty for knowledge, challenges & most importantly innovation. One of the passionate brain behind SpryOX

Leave a Reply

Your email address will not be published. Required fields are marked *