logo

Create Virtual Hosts in Apache wamp xamp

creating virtual hosts

When we install WAMP or XAMP for development purpose, it has one Virtual Host by default that is localhost. all projects or websites we create are sub-folders in that single Virtual Host.
and can can only put our projects inside default folder www for WAMP and htdocs for XAMP.
when we access our projects our urls are something like the following

the main domain in all above URLs is localhost. all the 3 projects are parts of that single domain.

What is Virtual Host

Virtual hosting is a method using which we can share resources of one single server to host multiple projects or website with separate domain names.

if we want to have separate domain name for each or some of our projects let say for above 3 projects we want domain names as

now all these domain names are different from each other and they hold separate domain names.
It is easy to setup, just note few points.

How to setup Virtual Hosts in Apache

I will be demonstrating the steps assuming you have installed WAMP server, for XAMP and MAMP there will be little paths differences.
to setup one or more Virtual Hosts we have to edit only 2 files

  1. c:\wamp\bin\apache\apache2.2.23\conf\extra\httpd-vhosts.conf
  2. c:\Windows\System32\drivers\etc\hosts

Step 1- Editing httpd-vhosts.conf

Goto c:\wamp\bin\apache\apache2.2.23\conf\extra\

First of all keep copy and paste this file so that you have a backup of it.

Open httpd-vhosts.conf in notepad or other editor and paste the following code

Using these Virtual Hosts we can also put our project source code in different folder (other than default wwww)
After saving changes, restart WAMP server.

Step 2- Editing hosts file

Goto C:\Windows\System32\drivers\etc\
open notepad as an administrative, and open hosts file
At the end write the following 3 lines one for each project Domain Name

Now you will be able to access each project as a separate Domain Name

Note: if you are hosting your sites on different port than 80 then you have to update httpd.conf file too accordingly to add Listen entries for those ports eg below

Isn’t it easy, let me know if you still have problem

Comments

  • Write a Reply or Comment

    Your email address will not be published. Required fields are marked *