Setting Up WordPress Virtual Hosts With XAMPP

I like to set up virtual hosts to set my local site in the exact configuration I will be using on the live server. This is also helpful when working with WordPress, as in this way I don’t have to stay changing URLs when uploading to the live site.

First up, find the hosts file on your Windows system, and add the following lines at the bottom of the file:

127.0.0.1    yoursite.com
127.0.0.1    www.yoursite.com

I would like to access my site both with the www and without, so I include them both. Save the hosts file and close it.

Now go to your Apache folder in XAMPP and locate the conf files. The are usually located at <<local path>>\xampp\apache\conf\extra

Open the file named httpd-vhosts.conf with a text editor (Notepad or Textpad for example).

Find this line ##NameVirtualHost *:80 and change it to NameVirtualHost *:80, thus we have activated it.

Now your final step is to adjust the following code as per your installation (make sure you have the directory letter right and the address to your site correct), then paste it at the bottom of the file:

<VirtualHost *:80>
DocumentRoot “E:/xampp/htdocs/”
ServerName localhost
ServerAlias localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot “E:/xampp/htdocs/yoursite”
ServerName www.yoursite.com
ServerAlias www.yoursite.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot “E:/xampp/htdocs/yoursite”
ServerName yoursite.com
ServerAlias yoursite.com
</VirtualHost>

That should be it! Restart your server and everything should be working fine.

Some other guides:

This guide shows you how to do this in Windows XP, but you can also easily find how to do this on other Windows OS by doing a quick search on Google for “Windows (your version) hosts file location”

http://www.tildemark.com/software/servers/setting-up-virtual-hosts-with-xampp-running-on-windows-xp.html

If that doesn’t work for you, try following the instructions here:

http://forums.whirlpool.net.au/forum-replies-archive.cfm/569991.html

Related posts:

  1. How to Edit Files on Windows Vista or Windows 7 and Mac OS X
  2. Setting Up Postfix for Multiple Virtual Domains
  3. Setting Hostname on Ubuntu Server
  4. How to Setup XDebug With XAMPP
  5. Setting Up Your Computer for WordPress Development

Leave a Comment

Let us know your thoughts on this post but remember to place nicely folks!