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 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 defaulthtdocs
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 myexample.dev> ServerAdmin admin@localhost.com DocumentRoot "C:/xampp/htdocs/myexample" # change this line with your htdocs folder ServerName myexample.dev ServerAlias myexample.dev <Directory "C:/xampp/htdocs/myexample"> Order allow,deny Allow from all </Directory> </VirtualHost>
- Notes:
- change
<VirtualHost myexample.dev>
to something like<VirtualHostwordpress.dev>
or<VirtualHost wordpress.loc>
. - Be sure to change your
ServerName
andServerAlias
with 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 myexample.dev #change to match your Virtual Host. 127.0.0.1 demo.myexample.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.
0 comments:
Post a Comment