XAMPP is a popular web server platform for Apache/PHP. XAMPP allows you to configure virtual hosts to run multiple websites on same server. In this article, we will look at how to create virtual host on XAMPP.
How to Create Virtual Host on XAMPP
Here are the steps to create virtual host on XAMPP.
1. Open Virtual Host file
Open httpd-vhosts.conf file located in xampp installation folder (e.g C:\xampp\apache\conf\extra\httpd-vhosts.conf) in notepad or other text editor.
Also read : How to Enable HTTP Strict Transport Security in Apache
2. Create Virtual Hosts
Let us say you want to create virtual hosts for 2 domains www.domain1.com and www.domain2.com with document root folders located C:/xampp/htdocs/domain1/ and C:/xampp/htdocs/domain2/ respectively.
In that case, add the following lines to your virtual host file.
<VirtualHost *:80> DocumentRoot C:/xampp/htdocs/domain1/ ServerName www.domain1.com </VirtualHost> <VirtualHost *:80> DocumentRoot C:/xampp/htdocs/domain2/ ServerName www.domain2.com </VirtualHost>
Also read : How Does RewriteBase Work with Example
3. Include virtual hosts
Open Apache configuration file C:\xampp\apache\conf\httpd.conf in a text editor. Scroll down to the following section and remove # from beginning, to enable virtual hosts.
#Virtual hosts
Include conf/extra/httpd-vhosts.conf
Also read : How to Change Apache Log Level
4. Restart XAMPP
Restart XAMPP server to apply changes. Open browser and visit www.domain1.com and www.domain2.com to verify that they are loading properly.
In this article, we have learnt how to setup virtual hosts in XAMPP. You can use it to host multiple websites and domains on a single server.
Also read : Apache File Permissions Best Practices
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.