Virtual Hosts on Apache 2.2
Posted by: HWL (
Date: November 07, 2012 04:56AM

I want to document and ask if what I did is the correct implementation.

I run several Apache virtual servers (v.2.0.x) and all configuration is done in the httpd.conf file. So for any new domain on my server, I add a :

<VirtualHost *:80>
ServerAdmin email here
DocumentRoot D:\Apache\htdocs\

restart and all is fine.

I implemented the WAMP server mostly for integrated MySQL. WAMP is using Apache 2.2.x.
I mod'ed the httpd.conf file by un-checking Include conf/extra/httpd-vhosts.conf and adding
<Directory "D:\wamp\www ">
Order Deny,Allow
Allow from all
above the virtual hosts directive.

I next went into the httpd-vhosts.conf file and added:

<VirtualHost *:80>
ServerAdmin email here
DocumentRoot D:\wamp\www\
ErrorLog logs/
CustomLog logs/ common


<VirtualHost *:80>
ServerAdmin email here
DocumentRoot D:\wamp\www

and restarted.

Everything seems to work OK.
Using my server name brings up "" which is the WAMPSERVER panel.
Putting in the IP address gives me a "Foridden You don't have permission to access / on this server."
Putting in the brings up the "" website.

If I use the alias or the Your Projects or the Your Aliases link on the WAMPSERVER homepage I get the site PREFIXED with the AMPSERVER name. (no harm I guess).

Any opinions on this method or improvements? Thanks.

PS - I did the WAMPSERVER to run WordPress but WP seems too difficult for business sites (unless they blog) so I am looking at GetSimpleCMS or CMSimple which don't even need the MySQL.

And I will secure MySQL, etc.

Thanks again.

Re: Virtual Hosts on Apache 2.2
Posted by: RiggsFolly (
Date: November 07, 2012 02:23PM

Here is a doc I did earlier.

HowTo: Create Virtual Hosts in WAMP


1. Create a new folder outside the wamp directory structure.
for example
but this can be on any disk drive visible to the PC running wamp

2. Create a subfolder in c:\websites for each site you want to create.
for example:

3. Edit the file C:\wamp\bin\apache\apachex.y.z\conf\extra\httpd-vhosts.conf
where x,y and z are the version numbers of apache that you actually have installed.

NOTE: If you are switching between 2 or more versions of apache this will have to be done to all your versions of apache in turn.

SUGGESTION: I like to use the format sitename.localhost to make it obvious to me that I am dealing with my localhost copy of a site, you may prefer another notation, thats ok, the word localhost has no actual defined meaning in this case, its just my way of naming my development versions of a live site.

example contents:
	# Use name-based virtual hosting.
	NameVirtualHost *:80

	## must be first so the the wamp menu page loads when you use just localhost as the domain name
	<VirtualHost *:80>
	    DocumentRoot "C:/wamp/www"
	    ServerName localhost
	    Order Deny,Allow
	    Deny from all
    	Allow from
    	# You would never want a remote user to see this wamp config page.

	<VirtualHost *:80>
	    DocumentRoot "C:/websites/site1"
	    ServerName site1.localhost
	    Options Indexes FollowSymLinks
	    <Directory "D:/websrc/www/site1">
			AllowOverride All
			Order Deny,Allow
			Deny from all
			Allow from
		    #If you want to allow access from your internal network
		    # For specific ip addresses add one line per ip address
		    #Allow from
	    	# For every ip in the subnet, just use the first 3 numbers of the subnet
	    	#Allow from 192.168.0

Add as many <VirtualHost> as you require so each of your sites have one, changing the DocumentRoot, ServerName and any other of the parameters as appropriate.
This also allows you to make SITE SPECIFIC changes to the configuration.

NOTE: This will make the wamp manager "Put Online" function no longer have any effect of your sites, so leave it OFFLINE.
If you want to put one or more sites online you will have to change the Allow commands MANUALLY in this my-vhosts.conf file.

To check your subnet do the following:
Launch a command window, and run
Look for the line "Default Gateway" in the output and use the third number in your Allow commands.

4. Edit your httpd.conf file and search for these lines, they are near the bottom of the file.
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

5. Add a line under these to include your vhosts file, this will cause apache to register their existance.
Leave the origial httpd-vhosts.conf unchanged, it may serve as a useful reference if you get something wrong.
Also make a backup of this file as if you re-install or upgrade wamp it may be lost.
Include conf/extra/my-vhosts.conf

6. While still editing your httpd.conf file search for
	#   onlineoffline tag - don't remove
	    Order Deny,Allow
	    Deny from all
	    Allow from


Add the following after the <\Directory> tag

<Directory "C:/websites/">
    Order Deny,Allow
    Deny from all
    Allow from

This is to set security on your new directory structure so that access to these new sites is only allowed from (localhost) and your internal network.
P.S. Your internal network will probably be something like 192.168.x.y, check your system first!

7. Now in order for your browser to know how to get to these new domain names i.e. site1.localhost and site2.localhost, we need to tell windows what IP address they are located on. There is a file called hosts that is a hangover from the days before Domain Name Servers (DNS) were invented. It is a way of giving nice easy rememberable names to IP address's, which of course is what DNS Servers do for us all now.

Edit your HOSTS file, this can be found in C:\windows\system32\drivers\etc
and is a file called "hosts", the file does not have an extension.
Windows protects this file so you must be an Administrator to be allowed to save changes to this file.

If you are using VISTA or Windows7/8 you may think you are an Administrator BUT YOU ARE NOT!!!!
So to edit this file you must launch your editor, or Notepad in a specific way to gain Administrator rights. To do this find your editors icon and launch it using the following key strokes:
Shift + Right Click over its icon, this will display a menu, click the item "Run as Administrator", and click "Allow" on the challenge dialog that will appear.

Now you are ready to edit the hosts file so navigate your editor to c:\windows\system32\drivers\etc\hosts

Add the following lines to this file   site1.localhost   site2.localhost
NOTE: You will need to add lines to this file for each new virtual host site you create.

8. In order for Apache to pick up these changes you must bounce apache.
Do this by: Wamp manager -> Apache -> Service -> Restart Service

You should now be able to use the address site1.localhost in your browser to get to your new sites.
Copy your sites code into the "C:/websites/xxxx" folder if you already have a site coded or,
place a quick and simple index.php file into the "c:\websites\xxxx" folder to proove it all works.

   <!DOCTYPE html><html lang="en-US">
   <meta charset="UTF-8">
   <?php echo '<div style="background-color:red;color;white;text-align:center;font-size:18px">HELLO FROM Site1</div>'; ?>

If you have used the new domain name ( site1.localhost ) and it has not found the site.
a. Check the changes to the hosts file.
b. Restart the "DNS Service" that runs in windows. This caches all doman names that you use in a browser so that the browser does not have to query a DNS Server each time you re-use a domain name. This may have cached your failed attempt but a restart is easy and should solve the problem and is quicker that re-booting windows, which should also work.
To do this launch a command window as an Administrator ( Shift + Left Click over the command window icon ) and run these 2 commands.

>net stop "DNS Client"
>net start "DNS Client"
Note: The quotes are required as there is a space in the services name.

Re: Virtual Hosts on Apache 2.2
Posted by: HWL (
Date: November 07, 2012 04:25PM

I am using my WAMP unit as a PRODUCTION server.
DNS is assigned by our name servers. I dont think the HOST file info makes any difference. And the naming convention is a reason for my last post.

Re: Virtual Hosts on Apache 2.2
Posted by: RiggsFolly (
Date: November 08, 2012 03:18AM

You would be better to put your live site into a totally seperate directory structure i.e. not in a subfolder of the www folder.

This will allow you to secure wamp and your site seperately.

eg add something like this to your vhost definition to give access to the world but only to the live site and not wamp itself.

<Directory "C:/websites/yyy">
Order Allow, Deny
Allow from all

In your vhosts file put this as your first vhost
<VirtualHost *:80>
ServerAdmin email here
DocumentRoot D:\wamp\www

this will allow wamp features to function normally, it makes it the defualt site as well which is only allowed access from so people trying to get into your system using the external IP address rather than the domain name will get refused by the basic wamp security.

Re: Virtual Hosts on Apache 2.2
Posted by: HWL (
Date: November 09, 2012 01:25AM

RiggsF - thanks for your time!

a couple of things...
you said:
"wamp features to function normally, it makes it the defualt site as well which is only allowed access from so people trying to get into your system using the external IP address rather than the domain name will get refused by the basic wamp security."

My default installation allows me to hit the WAMP index by either IP or domain name from "outside". Go figure. I renamed the index.php, and stuck an index.html page with the company logo in there.

I changed my http.conf (really httpd-default.conf). Now there is now no directory browsing.
ServerSignature off
ServerTokens Prod

I did create a web directory D:/htdocs. I then created a httpd-vhost.conf :

<Directory D:\htdocs>
Options +Indexes FollowSymLinks
Order Allow,Deny
Allow from all

and put it after my www WAMP VH (as you wrote) and before my other virtual directives.

All seems OK. Thanks

Edited 1 time(s). Last edit at 11/09/2012 02:22AM by HWL.

Re: Virtual Hosts on Apache 2.2
Posted by: RiggsFolly (
Date: November 09, 2012 10:19AM

If you leave WAMP set to OFFLINE you wont be able to see the basic wamp site from any other IP than localhost(

The security for your new folder is then set ( as you have done it ) in the VHOST config.

If required you could MANUALLY change the standard wamp config to allow access from your subnet by adding an Allow from 192.168.1 to the wamp folders and also the phpMyAdmin config.

Best of both worlds

Re: Virtual Hosts on Apache 2.2
Posted by: ludirois (109.113.231.---)
Date: November 10, 2012 11:32AM

hello i try to include conf/extra/my-vhosts.conf in the apache httpd.config but when i run all services i get the orange icon why?

Re: Virtual Hosts on Apache 2.2
Posted by: RiggsFolly (
Date: November 10, 2012 03:09PM

Because there is an error in your my-hosts.conf

look in the apache error log it should give you the error.

Sorry, only registered users may post in this forum.