Setting up Virtual Hosts for WordPress Multisite with XAMPP running on Windows 7

Setting up virtual hosts with XAMPP on Windows 7 is very straight forward and could be done in less than 5 minutes. But getting a custom domain mapped URL in a Windows environment is a bit of a trick, here is a tutorial on how to accomplish this.

Check out the updated post on getting Localhost Wildcard Subdomains setup

[sociallocker] [/sociallocker]

This is almost a tutorial for myself, because on and off for the last few months I’ve been trying to get a Virtual Hosts set up on my local Windows 7 machine so I can run WordPress and WordPress Multisite.

Currently I am using XAMPP to run Apache and MySQL, but it requires all local hosted directories to run under the “localhost” site, for example: http://localhost/demo or http://localhost/clientdomain.

Virtual Hosts WordPress

Really there is nothing wrong with the above, but I’ve got a few WordPress multisite installs running that mimic live sites that use wildcard DNS with sub-domains. So dealing with a local sub-directory becomes hard to test and build when the live site is running sub-domains.

So, this post will cover how I got a sub-directory Multisite install working in Windows 7 with XAMPP. I’ll also list some great posts which helped me get to my final goal.

The Steps

  1. First I am going to assume you’re using a Windows machine and have XAMPP installed.
  2. Open the XAMPP control panel application and stop Apache. Be aware that late Windows machines might run it as a service, so check the box to the left of the Apache module.
  3. Navigate to C:/xampp/apache/conf/extra or wherever your XAMPP files are located.
  4. Open the file named httpd-vhosts.conf with a text editor.
  5. Around line 19 find # NameVirtualHost *:80 and uncomment or remove the hash.
  6. At the very bottom of the file paste the following code:
    
    <VirtualHost *>
        ServerAdmin [email protected]
        DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
        ServerName localhost
        ServerAlias localhost
        <Directory "C:/xampp/htdocs">
            Options Indexes FollowSymLinks Includes ExecCGI
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
    
    

    With out that line of code you will lose access to your default htdocs directory. IE. http://localhost/ will be inaccessible.

  7. Now you can copy and paste the code above below to add your Virtual Host directories. For example I’m working on a site called Eatery Engine so the following snippet will allow me to work with sub-domains on my local install:
    
    <VirtualHost eateryengine.dev>
        ServerAdmin [email protected]
        DocumentRoot "C:/xampp/htdocs/eateryengine" # change this line with your htdocs folder
        ServerName eateryengine.dev
        ServerAlias eateryengine.dev
        <Directory "C:/xampp/htdocs/eateryengine">
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
    
    
      Notes:

    • change <VirtualHost eateryengine.dev> to something like <VirtualHost wordpress.dev> or <VirtualHost wordpress.loc>.
    • Be sure to change your ServerName and ServerAlias with the same as above.

  8. Next head over to your Windows host file to edit your HOSTS. the file will be located at C:/Windows/System32/drivers/etc/hosts, where hosts is the file. Open it with notepad.
  9. Look for
    # localhost name resolution is handled within DNS itself.
    #	127.0.0.1       localhost
    

    and add the following just after that line:

    # localhost name resolution is handled within DNS itself.
    	127.0.0.1       localhost
    	127.0.0.1       eateryengine.dev #change to match your Virtual Host.
    	127.0.0.1       demo.eateryengine.dev #manually add new sub-domains.
    
  10. Restart Apache and test everything.

Final notes

Be sure to do a fresh install for any WordPress Multisite installs that may require sub-domains. Thanks to Tildmark and some of the comments for finally pointing me in the correct direction. This old MU forum post and this stackoverflow post also helped.

And please if you’ve got questions or comments, leave them below.

Update June 2012

I started to have issues with multiple custom domains, and had to change a few lines in the httpd-vhosts.conf file. See new code below:

Note: WordPress strips backslashes, so below I’ve replaced them with forward slashes. I believe it with work regardless either way.


<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/Users/Austin Passy/Documents/InMotion Hosting/frostywebdev.com/html"
    ServerName frostyweb.dev
    <Directory "C:/Users/Austin Passy/Documents/InMotion Hosting/frostywebdev.com/html">
	Options Indexes FollowSymLinks ExecCGI Includes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/eateryengine"
    ServerName eateryengine.dev
    <Directory "C:/xampp/htdocs/eateryengine">
	Options Indexes FollowSymLinks ExecCGI Includes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Sidebar

Alternatively you can use a product like ServerPress, which handles the creation process for you! I was lucky enough to meet Stephen at a recent OC WordPress meetup.

Austin
Austin

πŸ’πŸ½β€β™‚οΈ Husband to Jeana.
⚾️ Dodgers & Brewers.
πŸ’» PHP Engineer.
πŸŒπŸΌβ€β™‚οΈGolfer; ~13 HDC.
🌱 Hydroponic Gardner.
🍿 Plex nerd.
πŸš™ '15 WRX, '22 Model 3 LR, & '66 Corvette C2.

Follow me on Twitter @TheFrosty & Instagram @TheFrosty.

Articles: 293

57 Comments

  1. Nice one. This would have come in handy a couple months ago. My biggest problem with running WP multi-site on my local dev box and using subdirectories has always been with creating links like /contact-us/ that send you back to the main site. This looks like it would have been a perfect solution had I not just left my windows machine.

    I’ll be passing this on the the WordPress Vegas meetup group. I’m sure they’ll dig it!

    • For sure! What are you using for your Apple now? Built in Apache or MAMMP, because I think MAMP Pro allows domain mapping through there UI.

  2. Thank you Austin, just what was I looking for. After testing all different config, finally found the solution for Win7. Thanks πŸ™‚

  3. Can we make it work with Domain mapping as well? I understand this is a further step than subdomains, but would be really cool if I could set up domain mapping on XAMPP.

  4. Cool tutorial. I have tried your procedure above but was getting error when was trying to access the sub-domains: when I tried to login to the first site created the page was redirected to the login page again and I can’t access the dashboard…
    After making some tests, reading more information in some forums finally I got it working fine in this way, step-by-step:
    1) After install Xampp I created the directory for the multisite, called mult.dev
    2) Then I have installed the WordPress with the Network in that directory
    3) In the httpd-vhosts.conf file I placed the following code:
    NameVirtualHost *:80

    DocumentRoot “J:/xampp/htdocs”
    ServerName localhost

    DocumentRoot “J:/xampp/htdocs/mult.dev”
    ServerName mult.dev
    ServerAlias *.mult.dev

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

    4) For the “hosts” file I added the following code:
    127.0.0.1 mult.dev
    127.0.0.1 siteone.mult.dev #that would be the first site to be created
    5) Then I came back to the Network admin area and created the “siteone” there. After, everything goes perfect.
    Thanks too much for your help! πŸ™‚

  5. i have this

    DocumentRoot “C:/xampp/htdocs”
    ServerName localhost

    DocumentRoot “C:/xampp/htdocs/wordpress”
    ServerName wordpress.dev

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

    but my adress still like this -> http://wordpress.dev/wordpress/

  6. I believe that this is just the ticket! Thanks for posting and with great precision.

    I am looking to add a multi-site WordPress network to my development environment and researching how to do the setup. This post is a good gateway.

    Silly question perhaps, but can this work on earlier versions of Windows (e.g., Vista) or is something peculiar to Windows 7? Hope to bypass Windows 7 with my next upgrade. πŸ™‚

  7. Its also worth mentioning that you might need to modify the httpd.conf manually so that the below in enabled:
    Include conf/extra/httpd-vhosts.conf

  8. I tried this and Apache just hangs when I try to start it. I am new to Apache, and all I need to do is change my DocumentRoot to “C:/xampp/htdocs/wordpress/wp-content” instead of “C:/xampp/htdocs” that Apache uses. I can access “C:/xampp/htdocs” locally if I need to.

    How can I do this with out all the virtual crap?

  9. thanks for the help really helped me to, this comment I’m taduciendo with a translator because I do not understand English, so it was really great but very helpful.

    unde_peru_2013

  10. With windows vista 64 – I could not find a directory called
    C:/Windows/System32/drivers/etc/hosts
    even searching there was nothing called hosts

    should I just create the new sub dirs and the hosts file?

  11. Great article Austin – looks like I just need to change my URLs in the database and it’ll work perfectly for me.

    I do a lot of testing on other computers (Macs, other Windows machines with older browsers, etc.) so I have set myself up with a static internal IP so I can look at the site anywhere within our network.

    Rather than localhost/project it’s 192.168.0.206/project.

    Any idea how I’d accomplish this for my IP address, rather than just localhost/… ?

    If I find a solution for this, I’ll let you know.

    • I found the solution to this. in the same hosts file (C:/Windows/System32/drivers/etc/hosts) you can put in your direct IP address on another computer (my dev computer is 192.168.0.206) and point the the same virtualhost domain to it!

      ie.

      192.168.0.206 eateryengine.dev

  12. thanks for help, now i want to create this in linux fedora then how this possible. its same or difference.

  13. WordPress site moving problem is about absolute url and absolute paths stored in database.
    This method help about absolute urls…
    Are there similar method about absolute paths?

    Thank you

  14. I have done everything just the way put above. But Apache could not start.
    Any solution?

    Thanks

  15. I had an issue saving the hosts file, its asking me to save as. Anyone have any suggestions?

    • Aaaand, never mind. Changed the files permissions for my account and worked perfectly! Great article!

  16. New issue, cant get apache to start back up. Attached vhost.config below.

    NameVirtualHost *:80
    
    
        ServerAdmin [email protected]
        DocumentRoot "C:/Users/Alex/Dropbox/Web Design/Htdocs"
        ServerName dropbox.localhost
        ServerAlias dropbox.localhost
        
            Options Indexes FollowSymLinks Includes ExecCGI
            Order allow,deny
            Allow from all
    

    Any help would be greatly appreciated.

  17. also you must check your httpd.conf for
    # Virtual hosts
    #Include etc/extra/httpd-vhosts.conf

    to uncomment this line

    Include etc/extra/httpd-vhosts.conf

    Thanks

    • Thanks! This bit of information was left out everywhere. Uncommenting “Include etc/extra/httpd-vhosts.conf” in the httpd.conf finally SOLVED my problem!

  18. modified the http-vhosts file like so:
    NameVirtualHost *:80

    ServerAdmin [email protected]
    DocumentRoot C:/xampp/htdocs/medPlatform_compressor_DB2″
    ServerName sanome.dev
    ServerAlias sanome.dev

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

    ServerAdmin [email protected]
    DocumentRoot C:/xampp/htdocs/medPlatform_compressor_DB2″
    ServerName sanome.dev
    ServerAlias sanome.dev

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

    Verified that the http.conf file has the vhost file included.

    Also the the host file has the following:

    127.0.0.1 localhost
    127.0.0.1 sanome.dev #change to match your Virtual Host.
    127.0.0.1 demo.sanome.dev #manually add new sub-domains.

    Apache won’t start up now. What did I do wrong or am I missing something?

    Thanks

  19. Thanks for the great tutorial. Here is what I’ve done.

    in file hosts

    ——–
    # localhost name resolution is handled within DNS itself.
    127.0.0.1 localhost
    127.0.0.1 dev.mysite.com
    ——–

    and in httpd-vhosts.conf

    ——–
    NameVirtualHost *:80

    DocumentRoot “D:\xampp\htdocs”
    ServerName localhost
    ServerAlias localhost

    DocumentRoot “D:\xampp\htdocs\www\dev2”
    ServerName dev.mysite.com
    ServerAlias dev.mysite.com

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

    ——–

    When I give dev.mysite.com in the browser url, it does not give any error and simply redirects me to “http://localhost/www/dev2” displaying my site properly, but displaying “http://localhost/www/dev2” in the URL, which defeats the whole purpose of virtual hosts. What am I doing wrong here? Anyone? Many thanks in advance.

  20. nice article but i perform all of above steps but my vitual host still not functioning it is giving error server not found

    NameVirtualHost *:80
    
        DocumentRoot C:/xampp/htdocs 
        ServerName localhost
        ServerAlias localhost
        
            Options Indexes FollowSymLinks Includes ExecCGI
            Order allow,deny
            Allow from all
        
    
    
        DocumentRoot C:/xampp/htdocs/frostbox 
        ServerName zend.localhost
        ServerAlias zend.localhost
        
            Order allow,deny
            Allow from all
        
    
    
    
    # 	127.0.0.1 zend.localhost
    

    can you help me?

  21. Thanks for these. I’ve been looking for a way to set this up but none of the ones I’ve seen didn’t work. This finally did it. Thanks a million.

  22. Dear Austin,

    I found this wamp server easy to implement virtual hosts:
    UWamp server, and this server you could develop using sqlite database successfuly, in others solutions the sqlite database creation demands extra configurations.

    Try this and write your impressions about, I migrate all projects from Xampp to UWamp.

    The only work tedious to do is update all hosts files from the local network statrions to use the virtual host name associated with the IP Address Fixed to access the local intranet. If the user don’t want use de IP Address to access the intranet site. It’s a hard work for great lans (above 20 stations).

    http://www.uwamp.com try you will like.

  23. This seems very usefull ,is it possible to implement this procedure with magento CE 1.9 ?

  24. Hi, I did all you said here, my vhosts works fine, except for 1 thing.

    I have this:
    myproject.com/index.php?signIn=1

    I put my user and pass, and I login to my project, but appears in the url:

    myproject.com\/index.php

    puts the “\” automatically. How can I fix it?

  25. Just used this and some updates have occurred to xampp/apache so this is the important change

     # AllowOverride All      # Deprecated
     # Order Allow,Deny       # Deprecated
     # Allow from all         # Deprecated
      Require all granted    # << New way of doing it
    
  26. Thank you for the article , this is really help full
    i just forgot to add this in my file

        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost
    

    and my Appache was not starting then i Google it and got you.
    πŸ™‚
    thanks again and keep it up

  27. Thanks for this explanation had some troubles with multiple domains and this fixed it!

  28. I am using window 8 and xampp server ,i have been having problems with my virtual host,i think is my httpd, how can i edit the httpd to work with it. Can anyone help me out,i will appreciate.

  29. i’ve got error i got this from my xampp control-panel
    11:59:55 AM [Apache] Error: Apache shutdown unexpectedly.
    11:59:55 AM [Apache] This may be due to a blocked port, missing dependencies,
    11:59:55 AM [Apache] improper privileges, a crash, or a shutdown by another method.
    11:59:55 AM [Apache] Press the Logs button to view error logs and check
    11:59:55 AM [Apache] the Windows Event Viewer for more clues
    11:59:55 AM [Apache] If you need more help, copy and post this
    11:59:55 AM [Apache] entire log window on the forums

  30. On some versions of Windows, you’ll need to run Notepad as administrator to edit C:/Windows/System32/drivers/etc/hosts. Just right-click and click “Run as administrator”.

  31. i have one problem to setup virtual host..
    i set virtual host but it is directly redirected to dashboard now whats the solution for it…?

Comments are closed.