Other Free Encyclopedias » Online Encyclopedia » Encyclopedia - Featured Articles » Featured Articles: Timex Indiglo Watches - The History of Timex Indiglo Watches to Zermatt Switzerland Hotels - Hotels in Zermatt

Virtual Host Apache - Setting Up a Virtual Host in Apache 2.2+ on Windows

local file hosts website1

Although it may seem otherwise at first, establishing a virtual host on Apache server is not difficult at all. In fact, the task is so common that there is a wealth of information available online on how to accomplish it. So why add another article to the mix? There are two reasons. One, most of the information deals with versions of Apache prior to version 2.2. Two, most information focuses on setting up a virtual host on Apache for an actual production server. This complicates every aspect of the process. Instead, we will focus on starting a virtual host in Apache 2.2+ on a Windows machine as a local test server. In doing so, we can strip the steps down even further, making it as simple as possible for the novice to understand.

The first step in the process is to edit the http.conf file. First, uncomment the following line by removing the pound sign (octothorpe):

#Include conf/extra/httpd-vhosts.conf

It is also necessary to append a block of code to this file, which assumes your websites are located at “C:\MyWebSites”:

<Directory “C:\MyWebSites”>
Order Deny, Allow
Allow from all

In the directory, “C:\MyWebSites”, each website has its own directory:


Assuming that the domain for these sites is website1.com and website2.com, you will define virtual hosts using the domain names website1.local and website2.local. The domain names do not have to match. In fact, you could name them whatever you like, but unless you have a purpose for doing so, keeping the names similar is a logical choice.

Next, we will need to access the httpd-vhosts.conf file mentioned in that line that you commented out earlier. In your text editor of choice, navigate to the very bottom of that document. There is a sample of a virtual host implementation here, each line commented out by a pound sign so that the system does not actually execute it. Leave that as is. You are going to append your new virtual hosts at the end of that one:


DocumentRoot C:\MyWebSites\WebSite1
ServerName website1.local

DocumentRoot C:\MyWebSites\WebSite2 ServerName website2.local

When you save and close the file, the process is essentially complete. The Apache web server has all of the instructions it requires to in order to serve pages from those websites using the domain names website1.local and website2.local. There is a step or two, however, in order to get Windows to play nice.

Note: There are no quotation marks around the paths above. Since there were no spaces, they were not required, and you should not use them unless necessary. Had the path been C:\My Web Sites\WebSite1, then the line would read:

DocumentRoot “C:\My Web Sites\WebSite1”

Now, if you were to type http://website1.local into your web browser, you would get a DNS error since your ISP’s DNS server has no knowledge of that domain. In Windows, we work around this by editing the HOSTS (no extension) file. Prior to making a DNS request, Windows checks here first, so this is where we will set the appropriate value.

Generally, you will find the hosts file here:


Alternatively, you will find it here:


In many cases, the hosts file will be empty save the header. If it does have entries, leave everything else alone, and append your data to the end of what is there: website1.local website2.local

Finish this step by saving and then closing the hosts file.

Next, access your web browser of choice and enter http://website1.local into the address bar, and hit enter. Assuming the website was working properly beforehand, you should now have access to a local copy of website1.

Note: When creating virtual hosts in Windows in this manner, it is possible that it will disable the default http://localhost. This is not a problem, and if you do not use it, you can ignore this. However, some people do require access to http://localhost, such as when using phpMyAdmin. In this case, you will need to define “localhost” just as you did your own virtual host in the httpd-vhosts.conf file:

DocumentRoot C:\Apache\htdocs ServerName localhost

Update the Apache path as necessary if you did not install it in the default path. In addition, do not forget add the virtual host to the hosts file: locahost

Visa Prepaid Credit Card - Benefits Of Visa Prepaid Credit Cards [next] [back] Virgin Islands Rentals - Deciding Which Island for Virgin Island Rentals

User Comments

Your email address will be altered so spam harvesting bots can't read it easily.
Hide my email completely instead?

Cancel or