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

Check out the updated post on getting Localhost Wildcard Subdomains setup

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 admin@localhost.com
        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 admin@localhost.com
        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.