logo

4 Steps to Apache with virtual host on Windows

logo

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. Or you could always try a web host.

Related posts:

  1. Warning AMPstart is spyware
  2. Using XAMPP on a thumb drive
  3. Installing or upgrading a WordPress Theme
  4. What’s wrong with XAMPP
  5. The easiest way to upgrade your WordPress blog

46 Responses to “4 Steps to Apache with virtual host on Windows”

  1. Eric Pement says:

    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)

  2. David says:

    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.

  3. Helmut says:

    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 ;-)

  4. Eric Pement says:

    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!

  5. Con says:

    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

  6. David says:

    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.

  7. Jay says:

    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

  8. Doc says:

    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?

  9. MSN says:

    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.

  10. Anthony Burns says:

    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.

  11. Jay Emmet says:

    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.

  12. Jay Emmet says:

    Hi again.
    Solved it: in the httpd-conf, the “root” needs to be determined. Example:

    Thanks.

  13. Jay Emmet says:

    Oops!
    Example:
    –> Directory >Driveletter:/xampp/htdocs/mywebsitefolder”<

  14. ghostdogg says:

    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

  15. ghostdogg says:

    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

  16. rami says:

    hi thanks, finally got somthing work.. excellent notes…just wonder how do u get to solve it…

  17. Nita says:

    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

  18. Jason says:

    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?

  19. [...] 4 Steps to Apache with virtual host on Windows [...]

  20. 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

  21. Kevin says:

    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?

  22. Jason says:

    Kevin,

    Change your slashes to forward slashes

  23. Philipp says:

    Hello Kevin,

    create a file with “lang.tmp” as name in your htdocs/xampp directory. That will resolve your problem.

  24. Reena says:

    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

  25. TJ says:

    Great Help! The only flaw are the path examples, but I see that’s been mentioned above already. Keep it up (and running).

  26. James says:

    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…

  27. Sunny says:

    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?

  28. David says:

    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.

  29. [...] 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. [...]

  30. Sunny says:

    @ David

    Yeah, the thumb drive accessibility can be very useful.

  31. lavanyakumar says:

    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

  32. David says:

    lavanyakumar

    change NameVirtualHost *:80 to lavanyakumar You will have to change the port Apache listens to in the main Apache config file.

  33. heru1703 says:

    Well, thank so much.
    I Don’t know this script,
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    Help, Me Please…

  34. Rick says:

    This worked for me with the addition of the following entry. Without it, I continued to get an permission denied error.

    ServerName myserver DocumentRoot “D:/myserver”

    Order allow,deny
    Allow from all

  35. [...] 4 Steps to Apache with virtual host on Windows. [...]

  36. Pete Clark says:

    >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.

    Of course, you mean “right click”, not “left click”

  37. Pablo says:

    The same issue. i’m only able to see the first vHost and not The 2nd vHost even with the configuration you have here.

    the first and the second only show the first vHost.

    have you ever seen this situation?? if any interest i can post my vHost configuration

    thanks!!

  38. [...] Así pues si ahora dejamos un archivo /data/dev1.mydomain/www/index.php con su pertinente echo “Hello World!”; podremos acceder directamente al mismo desde http://dev1.mydomain siempre que tengamos correctamente configurado correctamente el archivo archivo hosts. [...]

  39. Jacob Ball says:

    Hi everyone,

    I’ve just installed WAMP Server 2, using the above instructions as a starting point, but I’ve done it slightly differently:

    1. Edit hosts file (as suggested) and put 127.0.0.1 localhost.mysite
    2. Edited httpd.conf file by UNcommenting the lines:
    LoadModule userdir_module modules/mod_userdir.so AND
    LoadModule vhost_alias_module modules/mod_vhost_alias.so

    and further down:
    Include conf/extra/httpd-userdir.conf AND
    Include conf/extra/httpd-vhosts.conf

    3. Edited httpd-userdir.conf by adding:

    Options All
    AllowOverride All
    Order allow,deny
    Allow from all

    4. Edited httpd-vhosts.conf by adding:

    DocumentRoot C:/path/to/files
    ServerName localhost.mysite
    ErrorLog “logs/localhost.mysite-error.log”
    CustomLog “logs/localhost.mysite-access.log” common

    I needed to put the ErrorLog and CustomLog lines in for mine to work.

    5. Restarted all services, and voila! :)

    Hope that helps someone too.

    Cheers,
    Jacob

  40. Jacob Ball says:

    Bah, try with code tags:

    Options All
    AllowOverride All
    Order allow,deny
    Allow from all

    and

    DocumentRoot C:/path/to/files
    ServerName localhost.mysite
    ErrorLog "logs/localhost.mysite-error.log"
    CustomLog "logs/localhost.mysite-access.log" common

  41. nisha says:

    how can i configure to change document root in windows vita having apache2.2

  42. Jacob Ball says:

    nisha,

    Edit this line in the Apache httpd.conf file:

    DocumentRoot “c:/whatever/you/want”

    Cheers,
    Jacob

  43. Scoohh says:

    Hi,
    I followed exactly what is instructed above but when I entered “wordpress” on the address bar it only displays the root of the xampp (http://wordpress/xampp/).

    Can anyone help me please.

    Thanx!

  44. John says:

    Hey guys, is there a way to create a virtual host on just a thumb drive? I’m running xampp lite on my thumb drive originally on Windows XP Pro, but I’m going to do some work using a Mac at school. (To be clear, I want to work on multiple sites [located outside the xampp folder, which I assume will use the DocumentRoot line] on both Windows and Mac). What should I do? I appreciate any help!

  45. Alok says:

    Hi David,
    Can you please help. I am trying to set up virtual hosts but the index.html that is served is from the following folder when I try typing either

    //localhost or
    //aarmax.localhost

    in the address bar.

    My C:/xampp/apache/conf/extra/httpd-vhosts.conf file is set up as follows:

    NameVirtualHost *:80

    DocumentRoot C:/xampp/htdocs
    ServerName localhost

    DocumentRoot C:/xampp/htdocs/aarmax
    ServerName aarmax.localhost

    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all

    My hosts file has two entries
    127.0.0.1 localhost
    127.0.0.1 aarmax.localhost

    I using Windows Vista and XAMPP 1.7
    Please let me know what I am doing wrong.

  46. Jimmy says:

    @Philipp
    create a file with “lang.tmp” as name in your htdocs/xampp directory. That will resolve your problem.
    Thanks Philpp

Leave a Reply

logo
logo
Powered by Wordpress | Designed by Elegant Themes