How to: Setup Multiple Virtual Hosts in WAMP Server

WAMP, or Windows Apache MySQL PHP has been a very server for lots of PHP developers who uses Windows environment. These are mainly the freelancers who mostly uses laptops as their local development machines. Whatever may be the reason, but when you use WAMP, it becomes difficult to manage multiple application installed in same root. For example while we use WAMP as a development environment, we have different client specific projects residing in different folders in the root and whenever these projects needs to be uploaded in production environment, the absolute paths has to be manually change. What if we want to have different root folder for each client? Well, this is possible in WAMP using Virtual Hosts. Let us see how to setup the virtual hosts. First we need to modify two files to create virtual hosts:
  1. hosts file: This file is in the c:\windows\system32\drivers\etc\ folder
  2. httpd.conf file: This is in your Apache install’s ‘conf’ folder – e.g. c:\wamp\Apache2\conf\httpd.conf
The hosts files has entries which maps IP Address to a name. By default the name “localhost” is mapped to 127.0.0.1 IP Address.
127.0.0.1 localhost
Code language: HTML, XML (xml)
Now what we have to do is to simply add few more entries per client in this file. You may want to use your clients domain name as mapping key (e.g. viralpatel.local)
127.0.0.1 client1.local
Code language: HTML, XML (xml)
Add as many entries as you want in hosts file. Whenever you enter “client1.local” in your web browser, windows will first look into hosts file and if it gets the corresponding entry, it sends the request to that IP Address. Now we have to change httpd.conf. Open the httpd.conf file and search for something like:
'DocumentRoot 'c:/wamp/www''
Code language: HTML, XML (xml)
Add following code after the ‘DocumentRoot “c:/wamp/www”‘ entry in httpd.conf file.
NameVirtualHost 127.0.0.1 <VirtualHost 127.0.0.1> ServerName localhost DocumentRoot 'C:\wamp\www' </VirtualHost> <VirtualHost 127.0.0.1> ServerName myclient.local DocumentRoot 'C:\wamp\www\ClientsMyClient' </VirtualHost>
Code language: HTML, XML (xml)
And now you need to modify the code a bit to match the server name with the one from your ‘hosts’ file and the DocumentRoot with your clients file path.

View Comments

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

5 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

5 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

5 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

5 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

5 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

5 years ago