Site icon WDB24

How to Setup Multiple Virtual Hosts on XAMPP

xampp featured image

Virtual host is one of the best ways to host multiple domains. Virtual host can be IP based or name based. IP based means that difference IP address of different websites and home based means running multiple names in each IP address.

In local PHP development environment like xampp/wampp, virtual host is also helpful because it reduces base url problems and it is better to hit local.wordpress then localhost/wordpress.

In this tutorial I am going to show you how to setup multiple hosts on xampp. Because as a PHP developer, We are usually running multiple projects at a same time.

If you don’t have xampp on your local machine or you want to install xampp on your machine. Please read my below 2 posts according to your OS.

Steps: Setup multiple virtual hosts on XAMPP

I have installed xampp on my E:\ directory on windows.


Create Folders in Htdocs:

Go to your htdocs folder and create 2 folders test1 and test2. Now create index.php file in both of the folder and write “This is virtual host 1” and “This is virtual host 2” in test1/index.php and test2/index.php respectively.

Open httpd-vhosts.conf:

Now go to xampp/apache/conf/extra and open httpd-vhosts.conf. It wil look something like below.

Go to the last line of the file and paste below code.

Open hosts and add hosts:

Go to C:\Windows\System32\drivers\etc and open hosts file. Hosts file will look something like below.

Now go the last line of the file and paste below code.

Save hosts file as an Administrator user. If you don’t have administrator rights then copy hosts file to the desktop add above lines and then again copy desktop hosts file to the original and replace to the previous file.

Restart XAMPP:

Restart apache and mysql services on xampp and to go browser and type test1.local in tab and press enter and in other tab type test2.local and press enter. You will see below page.

If you will face any problem implementing above. Please feel free to post your question in below comments.

Also Read:

Exit mobile version