When testing websites I need to access more than just my standard Windows server at http://localhost. It’s possible to run more than one server using the Apache Virtual Hosts feature.
Note: I have XAMPP setup on my Windows XP system, which is running Apache 2.2.
I’ll display below how I set up my additional “paytest” virtual server.
First of all you’ll need to edit the Windows Hosts file. You can find this file in C:\WINDOWS\system32\drivers\etc\hosts. Edit it using Notepad.
Because I’m adding a “paytest” virtual host my updated file looks like;
# Copyright (c) 1993-1999 Microsoft Corp.## This is a sample HOSTS file used by Microsoft TCP/IP for Windows.## This file contains the mappings of IP addresses to host names. Each# entry should be kept on an individual line. The IP address should# be placed in the first column followed by the corresponding host name.# The IP address and the host name should be separated by at least one# space.## Additionally, comments (such as these) may be inserted on individual# lines or following the machine name denoted by a '#' symbol.## For example:## 102.54.94.97 rhino.acme.com # source server# 38.25.63.10 x.acme.com # x client host127.0.0.1 localhost127.0.0.1 paytest
Once you’ve saved the hosts file make sure your Apache server is not running.
Now we’ll need to edit the the Apache Virtual Hosts configuration file. My installation of Apache is in C:\xampp\apache so the file that I have to update is C:\xampp\apache\conf\extra\httpd-vhosts.conf.
My file now looks like;
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn’t need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option ‘-S’ to verify your virtual host
# configuration.#
# Use name-based virtual hosting.
#
NameVirtualHost *# this is the default mapping to http://localhost
<VirtualHost *>
DocumentRoot “C:/web/localhost”
ServerName localhost</VirtualHost>
# the new virtual host mapping to http://paytest/
<VirtualHost *>
DocumentRoot “C:/web/paytest”
ServerName paytest
<Directory “C:/web/paytest”>
Options Indexes FollowSymLinks Includes
AllowOverride All
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
Note that the NameVirtualHost entry at the top has been uncommented. That was my first mistake and Apache didn’t restart. Also be careful of typos as Apache won’t restart if you’ve typed something in incorrectly.
Once you’re happy with your addition then restart Apache.
You should now be able to vist http://localhost and http://paytest in your browser and the pages should now visit the appropriate folders.
If you have more customisations to make to your virtual sites (e.g. log files etc…) you can include the changes within each VirtualHost entry, like the Directory changes above.
Leave a Reply