Domain Directing and Virtual Host Setup for WAMP Server

0
1832

wamp_guy_leftearlAs with most developers who install WAMP you are probably working with localhost as your development domain name and directories for your projects.

For demonstration purposes lets say you are developing a WordPress or Joomla based site for Google where the domain is http://www.google.com

So you would typically create this directory structure where all your project files would reside, assuming Wamp is installed in the C Drive.

c:\wamp\www\google

 

Now you would be accessing this domain with the URL

http://localhost/google

 

And during your development life cycle all your links in the database and configuration will point to

http://localhost/google

 

This is not ideal when it comes time to migrate the site to the actual domain as now you will have to do some configuration and database maintenance to correct the links to point to the correct domain name.

So lets do it the right way.

Look in your Wamp installation directory and find the file named

httpd.conf

 

Scroll right to the bottom and you will see a couple of lines that look like

#IncludeOptional "c:/wamp/vhosts/*"
Include "c:/wamp/alias/*"

Uncomment the top line so it looks like making adjustments to reflect your Wamp installation path.

IncludeOptional "c:/wamp/vhosts/*"
Include "c:/wamp/alias/*"

Now find your Windows hosts. file which is generally located in

C:\Windows\System32\drivers\etc

You can try to directly open the file below in the text editor to save time trying to find it.

C:\Windows\System32\drivers\etc\hosts.

Once it is open the content will look something like this

# 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

Create a new line at the bottom with the line below without the hash(#) at the beging and save the file.

127.0.0.1 google.com

Now when ever you try to go to google.com your browser will look for the domain on your computer or localhost automatically, so if you need to access the actual domain just add the hash(#) in front and save or delete the line and save.

Next go to the follow directory

C:\wamp\vhosts

and open the fileĀ httpd-vhosts.conf for editing

For the sake of simplicity add this Apache directive towards the bottom of the file and save it, you can add extended parameters to the VirtualHost directive if you wish.

<VirtualHost *:80>
ServerName google.com
DocumentRoot "c:/wamp/www/google/"
</VirtualHost>

That’s it now restart Apache and enjoy development on your project with less hassle at the end.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here