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:
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.
- 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 email@example.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
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 firstname.lastname@example.org 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>
<VirtualHost eateryengine.dev>to something like
- Be sure to change your
ServerAliaswith 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.
- Restart Apache and test everything.
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.
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>