This tutorial is for XAMPP 1.7.3 running under Windows XP with Service Pack 3. It may be similar for other version combinations, but no guarantee is made.
Assumes you have installed XAMPP. Instructions can be found here.
UPDATE 17-March-2012:If you are running Windows 7 (and possibly Vista) the default security settings prevent you from running applications with administrative privileges. This means that you won’t be able to save changes made to the hosts file.
For instructions on opening the hosts file for reading and writing please see this article.
Installing XAMPP allows you to develop, test, and play around with web server code on your local machine. You can configure and test out your website locally, instead of live somewhere on the web.
It does have the drawback that to access your website you have to type localhost/my-web-site, where my-web-site is actually the directory you installed your website in.
You can setup the Apache Server in XAMPP to serve up web pages as though they were actually located on www.my-web-site.com instead of localhost.
This is a two step process: first, you have to redirect the web site name to your computer; next, you get Apache to redirect the web site address to your installed directory.
Redirecting the Web Site to Your Computer
When you type a web site name into the URL field (say, www.google.com), your browser sends the name to a Domain Name Server that looks up the text name (www.google.com, for example) and returns the Internet Protocol (IP) address for it (126.96.36.199 is returned for www.google.com). Your browser then connects to IP address 188.8.131.52.
Before your browser queries the Domain Name Server, it first checks a file called hosts on your computer. If the requested web site name is found, it uses the IP address found in the file.
1) Locate your hosts file. In Windows XP, this file is located in C:\WINDOWS\system32\drivers\etc:
NOTE: Different versions of Windows may store the file in a different directory.
2) Open the file with a plain text editor (like Notepad++). Using a word processor, like Word, can mess up the file when you save it.
It is very likely that the file is empty, except for the default comment and examples (the section in the green box):
3) Add lines containing the domain name(s) and IP address to redirect to. See the section in the red box in the image above.
Each line must begin with the address 127.0.0.1 (this is the localhost address)
After the IP address, type the name of the domain you wish to redirect to this address. You may only enter 1 name per line.
Addresses like my-site.com and www.my-site.com are different and each need a separate line.
Your address does need to be a “valid” top level domain (i.e. .com, .net, .ca, .pl, etc). It just needs to be composed of letters (a-z), numbers (0-9), hyphens (- but not as the start or end of a name) and periods (.). In the examples above, I used .15, .16, and .17 as the top level domain (which are not valid top level domains).
You can redirect existing domains to your machine. If you entered the line: 127.0.0.1 google.com, then every time you typed google.com into your URL field, your browser would redirect the request to your machine instead of going to Google’s web site. NOTE: this redirection only happens on your computer – everyone else in the world will still go to Google’s home page.
You can also redirect (on your computer only) one website to another. For example, suppose you are boycotting Google, so you decide to redirect google.com to bing.com instead. You would do that by entering Bing’s IP address in your host file followed by the web site you want to resolve to that IP address: 184.108.40.206 google.com
4) Save the changes.
5) Restart your browser (if it was open when you made the change to your hosts file).
Getting Apache to Serve Your Web Site
These instructions are for XAMPP 1.7.3. Other versions or XAMPP, or different Apache Server installations may have the files in different locations, or may even have the files named differently.
6) Locate the httpd-vhosts.conf file. For most XAMPP 1.7.3 installs this will be C:\xampp\apache\conf\extra (in my case, I installed XAMPP on my D-drive, so the folder is D:\xampp\apache\conf\extra):
7) Open the file using a plain text editor (like Notepad++). Using a Word processor, like Word, can mess up the file when you save:
The file will contain some documentation and sample virtual hosts.
8) Add, at the bottom of the file, new virtual hosts for each domain you added in step 3) above.
Each host will have the following form:
<VirtualHost *:80> ServerName www.joomla.16 ServerAlias joomla.16 DocumentRoot d:/xampp/htdocs/joomla16 </VirtualHost>
ServerName: following this label, add the name of the domain you added in step 3)
ServerAlias: following this label, you may add as many alternate domains (separated by spaces) as you like that are supposed to resolve to this virtual host. Remember that www.my-domain.com is different from my-domain.com, but, typically, you would want them to resolve to the same server.
DocumentRoot: following this label, add the path where your website is located. You can use an absolute path (as in the example above), or a relative path (but relative paths can be trickier to set up, so I prefer to use an absolute path).
9) Save the file.
10) Restart the Apache Server to have the change take effect. Do this by clicking on the Stop button on the XAMPP control panel and then clicking on the Start button. (You could also just reboot the computer, but that is overkill).
You should now be able to type the domain name into your URL field and go directly to your locally hosted web site:
For more information on configuring virtual hosts, you can read the documentation at the Apache Foundation here.
There is a lot more you can do with virtual hosts (such as adding an IP address).
Budget web hosting providers use virtual hosts to host multiple websites on the same server (and same IP address).