Feb 24 2010

How to create virtual hosts in Windows (wamp) web server?

Intro

Creating virtual hosts is the better way to simulate the hosting server in your own development server. Simply your localhost folders will act as domains where you can easily test several sites in the local server as http://mysite.local or http://mytest.mysite. To create this kind of virtual hosts or virtual domains in your Apache server on Windows using WAMP server is just a matter of editing few files. Find the walk-through below.

virtual-hosts

Step 1 – Setting up the ‘host’ file

  1. Find the ‘host’ file in ‘C:\WINDOWS\system32\drivers\etc’ folder (or where you installed windows)
  2. Open it with Notepade or any text editor.
  3. You will see following lines
  4. # Copyright (c) 1993-2009 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
    # localhost name resolution is handled within DNS itself.
    127.0.0.1       localhost 
    ::1             localhost
    
  5. Add the desired domain names in the end of the text (after the default localhost settings indicated above) it can be anything with or without extension (see the examples below)