setup apache virtual hosts

How to Setup Apache Virtual Host in Windows

Virtual Hosts allow you to run multiple websites on a single server. It reduces server costs and space in case you want to host multiple domains in one place. In this article, we will look at how to setup Apache virtual host in Windows.

How to Setup Apache Virtual Host in Windows

Here are the steps to setup Apache virtual host in Windows. Let us say you want to host 2 domains – and on a single server.

1. Update hosts file

Open the system hosts file, generally found at c:\WINDOWS\system32\drivers\etc\hosts in a text editor.

You will find the following line in it localhost

Add the following lines below it

You need to add 1 line for every domain that you want to host on your server. This will ensure that requests sent to these domains are routed to server on your machine.

2. Create folders for domains

Next, create separate folders, 1 for each domain in your Apache document root location C:/Apache24/htdocs. Each folder will host the files for that domain. For example, create C:/Apache24/htdocs/example1 and C:/Apache24/htdocs/example2 for and respectively.

Make sure the index.html or index.php file for is at C:/Apache24/htdocs/example1 and index.html or index.php file for is at C:/Apache24/htdocs/example2.

If you are using XAMPP then you need to create these folders at C:/xampp/htdocs instead.

3. Update Virtual Hosts in Apache Configuration

Open virtual host configuration file located at apache\conf\extra\httpd-vhosts.conf in a text editor.

Add the following VirtualHost tags 1 for each domain.

<VirtualHost *:80>
     DocumentRoot C:/Apache24/htdocs/example1
 <VirtualHost *:80>
     DocumentRoot C:/Apache24/htdocs/example2

If you are using XAMPP, then create your folders in C:/xampp/htdocs (or wherever your xampp installation is located) and update your virtual host configuration as shown.

<VirtualHost *:80>
     DocumentRoot C:/xampp/htdocs/example1
 <VirtualHost *:80>
     DocumentRoot C:/xampp/htdocs/example2

4. Check configuration file

Open Apache configuration file in XAMPP installation folder. Generally, it is located at C:/xampp/apache/conf/httpd.conf

Uncomment the following line in it by removing # at its beginning.

Include conf/extra/httpd-vhosts.conf

If you don’t find the above line you can add it afresh.

Restart XAMPP or Apache server to apply changes.

Open browser and go to you will see the index.html page of example.1com. Similarly, open and you will see the index.html page of

Also read:

How to Escape Percent Character in Apache using .htaccess
How to Log POST data in NGINX
How to Read POST data in NodeJS
How to Setup Catch-all Subdomains in NGINX
How to Uninstall NodeJS, NPM in Ubuntu

Leave a Reply

Your email address will not be published.