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/extraor wherever your XAMPP files are located. - Open the file named
httpd-vhosts.confwith a text editor. - Around line 19 find
# NameVirtualHost *:80and uncomment or remove the hash. - 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
htdocsdirectory. 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 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
ServerNameandServerAliaswith the same as above.
- change
- 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.
- 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>
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.
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.
Hands Down, I just did this. Although I am using MAMP PRO!
But I learn a lot from you austin
Thank you Austin, just what was I looking for. After testing all different config, finally found the solution for Win7. Thanks
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.
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!
Excellent! Thanks…
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/
Same here.
ServerAdmin admin@localhost.com
DocumentRoot “C:/xampp-portable/htdocs”
ServerName mgd.local
ServerAlias mgd.local
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
and my domain is still: http://mgd.local/mgd/
How did you end up solving it?
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.
This should work with any version of Windows.
Thanks, very helpful!
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
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?
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