4 Steps to Apache with virtual host on Windows
A common question that seems to come up often is; how do I setup virtual host on apache. I’m going to show you how to do this on apache running on windows. It really is very simple.
I’m going to show you how you can do this in 5 minutes, and just 4 steps. Before we start you will need to download a fresh copy of XAMPP Lite. Once downloaded, unzip the file. You do not need to install this it will run right out of the extracted directory. See if you can do this in 5 minutes. Post your results in the comment section below. Let’s get started:
Step 1 adding host name to windows
You will need to open your windows host file. Depending on your version of windows, this file will be located in different locations. Here is the list of where your host file will be:
Windows 3.1/95/98/ME:
c:\windows\hosts
Windows NT/2000/XP Pro:
c:\winnt\system32\drivers\etc\hosts or c:\windows\system32\drivers\etc\hosts
Windows XP Home:
c:\windows\system32\drivers\etc\hosts
Windows Vista:
C:\Windows\System32\Drivers\etc\hosts
Open the file with notepad. If your using Vista you’ll need to run notepad as administrator. Just left click on the notepad icon and click run as administrator in the drop down menu.
Now add this to the bottom of the file
127.0.0.1 wordpress
127.0.0.1 websitebaker
The number to the right is your computers default ip address. In most cases the number should be the same as I have listed here. The words are the virtual host name. In this case I am adding 2 new hostname, wordpress, for my WordPress directory, and websitebaker for my Website Baker directory.
Save the file. Make sure notepad doesn’t append .txt to the file. That’s it for step 1, see easy so far.
Step 2 Edit the httpd-vhosts.conf
Open the httpd-vhosts.conf file with notepad. You will find it in xampplite\apache\conf\extra. Copy and paste the following code at the end of the file.
<VirtualHost *:80>
DocumentRoot /xampplite/htdocs
ServerName localhost
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName websitebaker
DocumentRoot /xampplite/htdocs/websitebaker
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /xampplite/htdocs/websitebaker>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName wordpress
DocumentRoot /xampplite/htdocs/wordpress
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /xampplite/htdocs/wordpress>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now scroll back up and un-comment this line:
#NameVirtualHost *:80 (toward the top)
To look like this:
NameVirtualHost *:80
Save the file and create the 2 directories (wordpress & websitebaker) in your htdocs directory.
Step 3 Start Apache and test it.
go to \xampplite directory and click on xampp-control.exe and click the start button next to apache,
Watch for errors. If apache reports no errors then give your virtual host a try http://wordpress/
I hope you had fun, please comment your experience.
Step 4 (Okay, now I can count, with a little help from Eric)
Tell us about your experience by commenting bellow, and enjoy your XAMPP server.

On my copy of Apache, the config file is called “httpd-vhosts.conf” (note the ’s’).
Since this is a configuration for Windows, the reader should note that paths with embedded spaces will prevent Apache from loading at all. For instance, “c:/Program Files/xampp/htdocs/wordpress” will produce an error since it has an embedded space. The solution is to represent pathnames with embedded spaces by the old DOS 8-char short filenames, and keep the forward slashes (not backslash). Thus,
DocumentRoot c:/PROGRA~1/xampp/htdocs/wordpress
I also notice that there is no “Step 3″. Maybe it’s not needed? (smile)
I really do need to turn on my inner editor. Thank your for noteing the missing “s” will fix that.
Step 3 yea had to rewrite a few times, so my bad. LOL
The back slashes can be used in apache 2 on windows. I’ve been doing it that way for a while now.
The reason I didn’t give the full path is because with this setup you can move the package around, or use it on a thumb drive. but yes it’s a good idea to enclose the path in parentheses.
Thanks for your comments, They are always welcome.
Hi David,
thanks for this wonderful piece of work
There’s one part missing, I think: In the httpd.conf (in /xampp/apache/conf) you should also uncomment the line
#Include conf/extra/httpd-vhosts.conf
to
Include conf/extra/httpd-vhosts.conf
other wise apache won’t load the httpd-vhosts.conf
Also, strange enough, I have noticed that on my system I have to write
NameVirtualHost mydomain1.td:80
…
for *each* virtual host, e.g.
NameVirtualHost mydomain1.td:80
…
NameVirtualHost mydomain2.td:80
…
NameVirtualHost mydomain3.td:80
…
don’t know why, but it only works this way
A better way to test the new configurations is starting the apache_start.bat and watching the screen (the DOS box) and/or having a look at the error logs. xampp-control.exe only starts the server or not. I had a lot of trouble because there was sth wrong with the uncommented and adjustened
## ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log
## CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common
which I finally dropped. Now everything works fine
After some fiddling, I just found a solution to a CGI problem I have had. In my html forms, I like to have forms submitted to “/cgi-bin/foo.cgi” or “/cgi/bar.cgi”, and see the form processed from the /cgi folder for that web site. That way, the code that works on my development computer can be copied to the live server without any modification.
The fix was to copy over these 2 blocks of code, and insert them just before the closing “” tag:
ScriptAlias /cgi/ c:/xampplite/htdocs/wordpress/cgi/
AllowOverride None
Options None
Order allow,deny
Allow from all
Now I can run my cgi and php files from the /cgi folder for that website, instead of awkward workarounds!
It looks good. I tried Step 1. I saw:
“You do not have permission to save in this
directory. See the administrator to obtain
permission. Would you like to save in the My
Documents folder instead? Yes No”
I am using a public computer. What is the 1st
thing that I need to do, to go past this obstacle?
Thank you in advance. Con
Con, If your using a public computer, I would suggest not using virtual host. without the ability to add host names to the system I think you may be out of luck.
I have been struggling to get this right for a while now.. I’m running windows vista, and each time I try setup a v-host, I get an error when restarting the apache server, which leads to windows shutting the server.. Anyone else having this issue?
Thanks
Your example is fine if the two directories are on the same harddrive. My two directories are on two separate drives. what do I do in this case?
Hi, I have a similar problem to Doc (above)
I am trying to share a folder on my “D” drive, and the htdocs folder is on the “C” drive.
How would I go about adding this in as a virtual directory
f.e. main site C = http://www.domain.com and D = http://www.domain.com/files
Thanks.
I am encountering a rather strange problem with this. It works, but all the virtual hosts I set up end up going to the DocumentRoot of the localhost virtual host.
Hi.
Same as Anthony (above). I have set it all up as documented, but for some reason it jumps to the root - which is in my situation the xampp (full version) welcome screen. I am sure there is something simple to watch out for, but I can’t see it. Any help would be appreciated.
Thanks.
Hi again.
Solved it: in the httpd-conf, the “root” needs to be determined. Example:
Thanks.
Oops!
Example:
–> Directory >Driveletter:/xampp/htdocs/mywebsitefolder”<
I have edited the httpd-vhosts.conf file. I go to test the first site…works fine but when i test the second site it brins up the first sites home page…. any help. I have 2 domain names pointing to one ip setup in my dns admin page. Do i need to specify another port # :80 then :8080 for the other site(site 2)in my con fig file? Thanks for the help. ghost
Oh when i test from outside lan the 2nd domain name i get page cant be displayed….could be the domain registar has not finish stting up the dns change from their parked dns name..i checked the status and it didnt say that it was still “processing” my change…lets see what happens in a few days , thanks ghost
hi thanks, finally got somthing work.. excellent notes…just wonder how do u get to solve it…
Thanks David. It worked like a charm to me. I am using it on WindowsXP server for internal blog.
I think now I have to copy the files from the existing blog and paste it in this folder and then edit it. Hopefully I can edit the theme also.
Thanks once again for the clear instructions
ghostdogg,
I’m having the exact same issue. The 2nd virtual host listed in httpd-vhost.conf will always return the 1st host when you hit it with a browser. Did you ever solve your issue?
i have 2 host names that ties to my ip address ,but how do i set each to a different virtual site on my server
I’m trying to set it up this morning and … like many people … have some issues. I’m running XP Pro and the Full version of xampp. After following all the directions I go to http://wordpress/ and this is the error I get
Warning: file_get_contents(lang.tmp) [function.file-get-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\xampp\index.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\xampp\index.php:2) in C:\xampp\htdocs\xampp\index.php on line 4
Any thoughts?
Kevin,
Change your slashes to forward slashes
Hello Kevin,
create a file with “lang.tmp” as name in your htdocs/xampp directory. That will resolve your problem.
Hi, thank u for replying my entrecard drop. i have blogroll your site in my serious droppers list. I visit all the sites in this list almost everyday plus most of my visitors too. We all have the same idea of getting return drop cards. Hope that you can blogroll my site back in your web too.
Thank you,
Reena http://reenashwina.blogspot.com
Great Help! The only flaw are the path examples, but I see that’s been mentioned above already. Keep it up (and running).
I can see that you know how to install this really well, but my question is…how the heck do you uninstall it?
I’ve been half tempted to just delete the file, but I remember going through the installation and all the stuff I had to add to the registry, etc. I just want it off my system completely and as cleanly as possible (I don’t know why it doesn’t just come with an uninstaller) because I shut down my design business to take time for other things…so I don’t need it any more.
Any help would be much appreciated, I have been frustrated with trying to figure out how to get rid of this for weeks now…
Hi David, long time since I wrote, how are thing?
I use a WAMP server on my local, would that not be a simpler alternative to XAMPP?
Hey Sunny,
Doing very well thanks.
WAMP may work for some but I really like XAMPP There is no need to install with the lite edition, so I can move the server via a thumb drive to other systems.
Plus I’ve been using this package for a long time… I know it pretty well.
@ David
Yeah, the thumb drive accessibility can be very useful.
Hi
I am trying to configure virtualhost in apache
below is my sample file
NameVirtualHost *:80
DocumentRoot “D:\bea\user_projects\BASDomain\applications\smbasapp”
ServerName 172.24.121.189
Options FollowSymLinks
AllowOverride All
ServerName smbasapp
DocumentRoot “D:\bea\user_projects\BASDomain\applications\smbasapp”
Options FollowSymLinks
AllowOverride All
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
One problem from my side In: I want place http://localhost:7001
it is possible , I am trying but I am fail..please help
lavanyakumar
change NameVirtualHost *:80 to lavanyakumar You will have to change the port Apache listens to in the main Apache config file.
Mar 6th, 2008 at 2:13 pm
[...] 4 Steps to Apache with virtual host on Windows [...]
Apr 20th, 2008 at 4:34 pm
[...] It would also be a good idea to install a server on your home system. I use XAMPP Lite and have written a tutorial on running it with virtual host. [...]