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.
-
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. -
Search for “LoadModule vhost_alias_module” (without the quotes) and uncomment the
LoadModule vhost_alias_module modules/mod_vhost_alias.so
directive below. -
Search for “Virtual Hosts” (without the quotes) and uncomment the
Include conf/extra/httpd-vhosts.conf
directive below. -
Save and close the
httpd.conf
file.
-
-
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
. -
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.
-
Save and close the
httpd-vhosts.conf
file.
-
-
Update Your Windows Hosts File
-
Open your Windows hosts file located in
C:\Windows\System32\drivers\etc\hosts
. -
Add a new entry for the vhost you created in step 2.
-
Save and close the
hosts
file. -
Resart All Services in WAMP, pop open a web browser and access your new virtual host. Celebrate!
-
Comments