Skip to content

Instantly share code, notes, and snippets.

@dejanmarkovic
Created November 13, 2013 20:50
Show Gist options
  • Select an option

  • Save dejanmarkovic/7456168 to your computer and use it in GitHub Desktop.

Select an option

Save dejanmarkovic/7456168 to your computer and use it in GitHub Desktop.
Setting up Virtual Hosts for WordPress Multisite with XAMPP running on Windows 7
This is almost a tutorial for myself, because on and off for the last few month I’ve been trying to get a Virtual Host set up on my local Windows 7 machine. 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.
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-directories becomes hard to test and build when the live site is running sub-domains.
So, this post will cover how I got sub-directory multisite installs working in Windows with XAMPP. I’ll also list some great posts which help me get to my final goal.
The Steps
First I am going to assume you’re using a Windows machine and have XAMPP installed.
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.
Navigate to C:/xampp/apache/conf/extra or wherever your XAMPP files are located.
Open the file named httpd-vhosts.conf with a text editor.
Around line 19 find # NameVirtualHost *:80 and uncomment or remove the hash.
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.
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.
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.
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.
127.0.0.1 site1.eateryengine.dev #manually add new sub-domains.
Restart Apache and test everything.
Final notes
Be sure to do a fresh install for any WordPress Multisite installs that may require sub-domains.
And 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.
Update
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>
Source: http://austinpassy.com/2012/setting-up-virtual-hosts-wordpress-multisite-with-xampp-on-windows-7/
and updated with solution form here http://austinpassy.com/2012/setting-up-virtual-hosts-wordpress-multisite-with-xampp-on-windows-7/#comment-494
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment