Setup a Virtual Host in WampServer 3.0

A virtual host (vhost) is recommended to prevent uploading conflicts between your local and live site. It sets the project name as the document root, rather than localhost to avoid directory issues and better match a live server environment. WampServer 3 offers an incredibly easy way to create virtual hosts for your projects.

Virtual Host Setup

Steps:

  1. Create a project folder in the www directory (e.g. project1).
  2. Launch WAMP and navigate to http://localhost/.
  3. From the Localhost page, Click on Add a Virtual Host at the bottom left.
  4. Name the Virtual Host name in the first field. Use the same name as the project (e.g. project1). Set the complete path to the project in the third field (e.g. C:/wamp64/www/project1/). Finally, click Start the creation of the VirtualHost (May take a while) button. Upon completion, you should receive,
    The files have been modified. Virtual host project1 was created.
  5. Restart the DNS:
  • Right-click the green WAMP icon
  • Go to Tools
  • Restart DNS

If you go back to http://localhost/, test to make sure your project can be accessed under Your Projects and that the URL root is the project name instead of localhost. You should also have a new VirtualHost created under YourVirtualHost.

When we created the vhost using the GUI, 2 files were updated:

--httpd-vhosts.conf

Location: C:\wamp64\bin\apache\apache2.4.23\conf\extra

# Virtual Hosts

<VirtualHost *:80>
	ServerName localhost
	DocumentRoot c:/wamp64/www
	<Directory  "c:/wamp64/www/">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		Require local
	</Directory>
</VirtualHost>

<VirtualHost *:80>
	ServerName kriswignes
	DocumentRoot "c:/wamp64/www/kriswignes"
	<Directory  "c:/wamp64/www/kriswignes/">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		Require local
	</Directory>
</VirtualHost>

--hosts

Location: C:\Windows\System32\drivers\etc

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#

127.0.0.1 localhost
::1 localhost
127.0.0.1	kriswignes
::1	kriswignes