The Windows Apache MySQL PHP (WAMP) server is incredibly
powerful. Not only does it allow you to host a website using the world’s most
flexible web server, it also allows you to do so on your Windows host.
But don’t think because you’re on a Windows host that you
lose much of the flexibility found on the Linux equivalent. In fact, much of
the feature set translates — this includes virtual hosts. Using virtual hosts
allows you to, effectively, host more than one site on a single machine.
For example, say you want to host:
I’ll show you how to easily do both with a single WAMP
server (I assume the WAMP server is up and running, and you have administrative
access to the files and folders on that machine). We’ll focus on one
configuration file at a time.
First, you need to edit your hosts file on the server. This
will map the virtual host name to an IP address. To keep this simple, we’ll map
127.0.0.1 to mysite. Here’s how:
- Open Notepad as the administrator.
- Open the file
- Add the line: 127.0.0.1 mysite.
- Save the host file (making sure to not save it
as a .txt file).
The fastest way to access this file is to right-click the
WAMP icon in the system tray and select Apache | httpd.conf (Figure A).
The WAMP user menu
When you select the httpd.conf entry, Notepad will open with
the contents of the httpd.conf file. Within this file, you need to uncomment
out the entry for virtual hosts configuration file location. Search for these
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
Remove the “#” in the second line above and save and close the
The next file to edit cannot be accessed through the WAMP user interface;
you should find this file in C:\wamp\bin\apache\Apache-XXX\conf\extra\ (XXX is
the release number). Open that file in Notepad and add the following section
(we’re sticking with our current example of “mysite”).
CustomLog "logs/mysite-access.log" common
Notes about the code: You must
add a <VirtualHost *:80> directive for every virtual host you create. The
site administrator is email@example.com.
Also, if you need to serve the virtual host on a non-standard port, change it
in the VirtualHost directive line. The reference to c:\MYSITE is the directory
created to host the files and folders for the new virtual host; you’ll need to
create that folder (you can place it wherever you need in the folder hierarchy
as long as it is accessible by Apache).
After you add the above code to the correct file, save it and restart your
WAMP services. Now you should be able to see both localhost and mysite from
your browser. You’ll want to change those addresses to match your needs.
Also read on TechRepublic: Create aliases on your WAMP server
Subscribe to the Innovation Insider Newsletter
Catch up on the latest tech innovations that are changing the world, including IoT, 5G, the latest about phones, security, smart cities, AI, robotics, and more. Delivered Tuesdays and Fridays