IndoDX

Source for Everything

Virtual Host on Windows with XAMPP

On my first tutorial we was try to Installing WordPress on Windows use XAMPP, this time I will give little help again how to tweak our local server, and make it Virtual Host enable. So we can develop many many website in one time and still in our windows local machine.

This tutorial also work on Mac OSX, Linux Desktop, FreeBSD Desktop with little tweak.

What we need?
XAMPP Logo


Let’s get started.
After XAMPP Installed, go to you XAMPP Installed folder. After opened try to edit this file with Notepad++ for more easy way or use Notepad for old way..

Apache > Conf > Extra > httpd-vhosts.conf

After that, try to look this original configuration

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn’t need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <url :http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option ‘-S’ to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <virtualhost> block.
#
##</virtualhost><virtualhost *:80>
## ServerAdmin webmaster@dummy-host.example.com
## DocumentRoot /www/docs/dummy-host.example.com
## ServerName dummy-host.example.com
## ServerAlias www.dummy-host.example.com
## ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log
## CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common
##</virtualhost>
##<virtualhost *:80>
## ServerAdmin webmaster@dummy-host2.example.com
## DocumentRoot /www/docs/dummy-host2.example.com
## ServerName dummy-host2.example.com
## ErrorLog @rel_logfiledir@/dummy-host2.example.com-error_log
## CustomLog @rel_logfiledir@/dummy-host2.example.com-access_log common
##</virtualhost>
#<virtualhost *:80>
# ServerAdmin webmaster@lab.lokal
# DocumentRoot “C:/Program Files/xampp/htdocs/lab”
# ServerName lab.lokal
# ErrorLog @rel_logfiledir@lab.lokal-error_log
# CustomLog @rel_logfiledir@lab.lokal-access_log common
#</virtualhost>
#<virtualhost *:80>
# ServerAdmin webmaster@localhost
# DocumentRoot “C:/Program Files/xampp/htdocs/smf”
# ServerName localhost
# ErrorLog @rel_logfiledir@localhost-error_log
# CustomLog @rel_logfiledir@localhost-access_log common
#</virtualhost>


Look on that code, is that really long code and if work in Apache, if code have this # the code didn’t executed by Apache server.

Now we will try to add one virtual host, just edit all code above become like this below.

NameVirtualHost *:80
<virtualhost *:80>
ServerAdmin sampe@mysample.com
DocumentRoot “C:/Program Files/xampp/htdocs”
ServerName localhost
</virtualhost>
<virtualhost *:80>
ServerAdmin webmaster@mywordprees.com
DocumentRoot “C:/wordpress
ServerName www.wordpress.local
ServerAlias wordpress.local
<directory “C:/wordpress”>
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<limit GET POST OPTIONS>
Order allow,deny
Allow from all
</limit>
<limitexcept GET POST OPTIONS>
Order deny,allow
Deny from all
</limitexcept>
</directory>
</virtualhost>

On code above I try add two virtual host, the first one for take original http://localhost, and the second one for my WordPress virtual host http://wordpress.local

After code was completed, safe and exit.

Now, the magic time, in windows and many Operating Sytem, before they looking another DNS Server, many OS will check they hosts list on they machine, so let add new domain to our hosts machine.

Open you fave editor (Notepad++) for me, and Open File on this folder

C:\WINDOWS\system32\drivers\etc\

And select hosts
You will find this code

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost

That original Windows hosts, and this the time to add some host on you local machine to enable virtual host, below 127.0.0.1 localhost add this

127.0.0.1 wordpress.local
127.0.0.1 www.wordpress.local

That all, after that restart you Apache and try to point you Browser to new address, and holla you are dona add virtual host on you own local machine.

Popularity: 48% [?]

Share and Enjoy:
  • del.icio.us
  • Facebook
  • Digg
  • Reddit
  • co.mments
  • Furl
  • Ma.gnolia
  • BlinkList
  • NewsVine
  • Print this article!
  • Spurl
  • YahooMyWeb
  • E-mail this story to a friend!
  • LinkedIn
  • StumbleUpon
  • Sphinn
  • Yahoo! Buzz

8 Responses to “Virtual Host on Windows with XAMPP”


  1. Vikram says:

    Like your tutorial.
    Got Virtual Host running.

    Thanks

  2. Ben Clapton says:

    Great post, was very helpful in setting up my multiple hosting arrangement.
    Took some sorting out to make sure it would work, so I thought I’d share what I did here.

    I was using xampp, so added the details in the http-vhosts.conf file, saved, then tried to restart - and apache just wouldn’t restart. Deleted everything I had changed and it worked fine. But I didn’t have the multiple hostings.

    I took a look through the info on the Apache website, and read through the httpd.conf file, and then realised a couple of things.

    The first entry in your http-vhosts.conf file must have exactly the same detail as what’s in your httpd.conf file.

    Also, I don’t think I realised that the DocumentRoot had to be in “Inverted Commas” - they are in your post, I just don’t think I recognised that at the time.

    But I’ve now got it set up and will be hosting my websites from there soon!

  3. Franz says:

    This works great! You just made me so much more productive.

  4. Jesse says:

    I have a server running on linux, but I want to run an XAMPP server too.

    How can I set it up so that I can access the XAMPP server remotely?

    Is there a way to change the adress to access the server?

    (anyway, thanks for the tut. :D)

  5. Andrew says:

    WTF? Do you use XAMPP? Does it require conf editing? Oh guys, visit russian site denwer.ru . If it’s difficult to you to understand it, go directly
    http://www.denwer.ru/dis/Base/Denwer3_Base_2008-01-13_a2.2.4_p5.2.4_m5.0.45_pma2.6.1.exe
    it will create sites and subdomain as fast as you add diretory to Z:\home\yoursitename\www\ + all alias.
    It’s really easy to test locally ;)

  6. bryant says:

    I didnt use:
    Apache > Conf > Extra > httpd-vhosts.conf
    just to make it work. Although I want to place it there. The problem is I cant make it work. I havent tried:

    “The first entry in your http-vhosts.conf file must have exactly the same detail as what’s in your httpd.conf file.” as suggested by Ben. So my hosting entry is on httpd.conf. And of course, I set the hosts file on Windows.

  7. Stephan says:

    Thanks, works great for me on Vista 32-bit. I’ve been trying to figure out vhosts forever!

  8. epox says:

    if you copy this text directly and edit your settings, you should get in trouble because the ” are not correctly parsed, i retyped the ” and it works


Trackbacks/Pingbacks

  1. Jauhari Didetik | Seting Virtual Host di XAMPP Windows 22 06 08
  2. links for 2008-06-24 | Conteúdo Interativo 24 06 08

Leave a Reply