Virtual Hosts - all redirect to the WAMP localhost 'home' page Virtual Hosts - all redirect to the WAMP localhost 'home' page apache apache

Virtual Hosts - all redirect to the WAMP localhost 'home' page


Your hosts file looks good, but your virtual hosts definitions are not so good.

If you change your hosts file you can reload the windows cache by doing this from a command window that has been launched using Runs as Administrator or a simple reboot :-

net stop "DNS Client"

then when that completes do

net start "DNS Client"

Quotes required as there is a space in the service name!!

The DNS Client service caches domain names accessed and is pre loaded with domain names that exists in the HOSTS file at boot time or if you restart the service as above.

When debugging a new vhost definition, remember, that if something is wrong with a definition you are attempting to access, Apache will always default to the first vhost defined in the vhost definition file. So if thats where you end up i.e. the WAMP homepage, you can assume you made a mistake defining that vhost.

This also means that if you define that first vhost definition with something like Require local a random hack on your system should also be sent there, if that has its security set to Require local the hack should receive a 404 error which might discourage further hack attempts.

// My virtual hosts file<VirtualHost *:80>  ServerName localhost  DocumentRoot "C:\wamp\www"  <Directory "C:\wamp\www">     AllowOverride All     # never want to allow access to your wamp home page area to anyone other than This PC     # plus us the Apache 2.4.x syntax and not the 2.2 syntax     Require local  </Directory></VirtualHost><VirtualHost *:80>  ServerName client1.localhost  DocumentRoot "C:\wamp\www\client1"  <Directory "C:\wamp\www\client1">     AllowOverride all     # use Apache 2.4 syntax to all access to your internal network only     Require ip 192.168.0     # Or if you really want to give access to the whole internet uncomment this and comment the previous line     #Require all granted </Directory> DirectoryIndex index.html index.php</VirtualHost><VirtualHost *:80>  ServerName client2.localhost  DocumentRoot "C:\wamp\www\client2"  <Directory "C:\wamp\www\client2">     AllowOverride all     # use Apache 2.4 syntax to all access to your internal network only     Require ip 192.168.0     # Or if you really want to give access to the whole internet uncomment this and comment the previous line     #Require all granted  </Directory>  DirectoryIndex index.html index.php </VirtualHost>

If you don't actually want the world to be allowed access to these client sites, but you do want to be able to access the site from other PC's on your internal network then a better access mechanism would be to use Require ip 192.168.0. Note the use of just the first 3 quartiles of your subnet ( yours may not be 192.168.0, but a lot of routers default to that. Check your subnet first )

Also if you do want the world to see these client sites then you have to Port Forward your router as well.

Also if you didn't intend to give access to these site to the whole world, but were just following bad advice, a much more secure definition of all these sites would be to use Require local so you can only access them from the PC running WAMP.

WAMPServer 2.4, which I assume you mean when you say you are running the latest release of WAMPServer actually changed the the way that you can include vhost definitions. Well actually it included a new way and kept the old way as well.

So to include the vhost definition you can do one of these 2 things :-

1.Put your vhost definitions into the file \wamp\bin\apache\apache2.4.4\conf\extra\httpd-vhosts.conf and then in thehttpd.conf file uncomment this line ( its near the bottom of the conf file.

# Virtual hosts#Include conf/extra/httpd-vhosts.conf

Remove the # infront of the Include line

# Virtual hostsInclude conf/extra/httpd-vhosts.conf

2.Place your vhost definitions into a file 'called anything you like' into the \wamp\vhost folder.

There is a line at the bottom of the httpd.conf file now that say IncludeOptional "d:/wamp/vhosts/*"This will include any file in that folder and if it is a vhost definition it will apply that to the config. This is a new command to Apache 2.4 I believe so will only work on Apache 2.4.x installs.


Firstly, your directory structure should never go above the www folder for security purposes.

- c:\wamp\www (home)    -c:\wamp\www\client1 (client1)    -c:\wamp\www\client2 (client2)

Secondly changed in the vhost require a reload, but in your case, you must do a restart as wamp doesn't offer reload.


Try to put your client folders under C:\wamp\www\ like this C:\wamp\www\ client1 and C:\wamp\www\client2

EDIT

If still doesn't work try thischange your hosts file with client1.dev instead of client1.localhost and then put a Servername in you Virtualhost settings like this

<VirtualHost *:80>DocumentRoot "F:\www\client1"ServerName client1.devServerAlias client1.dev www.client1.devOptions Indexes FollowSymLinks<Directory "F:\www\client1">    AllowOverride All    Order Deny,Allow</Directory></VirtualHost>

You have to restart again to make the changes in hosts file work