How to set up multiple virtual hosts on XAMPP windows
It requires two main steps:
- Add Virtual Host Entries to vhosts Configuration file.
- Assign IP to your “Virtual Host”, editing windows hosts file.
STEP 1:
Open Config file:
drive:\\(xampp-installation-path)\apache\conf\extra\httpd-vhosts.conf
in my case it is located here:
C:\Server\xampp56\apache\conf\extra\httpd-vhosts.conf
Remove Comment for below line:
##NameVirtualHost *:80
Add Following Entry:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot "C:/Server/xampp56/htdocs/mistersuraj" ServerName mistersuraj <Directory "C:/Server/xampp56/htdocs/mistersuraj"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
Important Note: You will have to change DocumentRoot
, Directory
and ServerName
Change DocumentRoot
and Directory
to absolute path of the directory that contains your website files.
In my case it is:
C:/Server/xampp56/htdocs/mistersuraj
In Your case it can be:
C:/Server/xampp56/htdocs/your-project
OR anything you like but it must exists in your computer.
Both DocumentRoot and Directory must have same path.
Change ServerName
to “Anything you like” but please give simple string to make your life easier. lets make it “your-project”
In my case it is:
mistersuraj
and I can access it like http://mistersuraj/
in my browser
In Your case it can be:
your-project
and You can access it like http://your-project/
in your browser
Virtual Host Config is done. Lets move to second step:
STEP 2:
Open your Windows hosts config file ( hosts )
it is usually here: C:\Windows\system32\drivers\etc
you need administrator privileges to edit the file
Add this entry to hosts file:
127.0.0.1 your-project
So that it will look like this:
127.0.0.1 localhost
127.0.0.1 your-project
Important Note: Ensure you have single ip and string in each line.
We are done!!!
Restart Your XAMPP
Open your newly created url in your browser : http://your-project/
You can as many virtual hosts you want but for each host you must have entries in httpd-vhosts.conf and windows hosts file.
Important Note: If you have .htaccess
file in your folder ensure you have correct RewriteBase
path set. It can work with RewriteBase /
only
Leave a Reply