When working on multiple projects locally, accessing them via http://localhost/projectname can be inconvenient. Setting up Virtual Hosts in XAMPP allows you to create custom domain names like thecreativecoders.local, making development easier and more professional.
This guide will walk you through setting up virtual hosts in XAMPP to run multiple sites locally using custom domain names.
What is a Virtual Host?
A Virtual Host allows you to assign a custom domain name (e.g., ) to a project folder inside XAMPP’s thecreativecoders.localhtdocs. Instead of accessing your project via http://localhost/, you can access it via thecreativecodershttp://thecreativecoders.local.
Virtual Hosts are commonly used to:
- Run multiple websites on a local server.
- Mimic live website domains for accurate testing.
- Improve organization when working with multiple projects.
Why Use Virtual Hosts for Development?
- Professional Development: Simulates a real domain environment (
).thecreativecoders.local - Easier Site Management: Avoids long URLs like
localhost/.thecreativecoders - Better Testing: Treats
localhostdifferently from a real domain, so virtual hosts ensure smoother migration to live servers. - Multi-Site Support: Allows you to work on multiple installations simultaneously.
Step 1: Enable Virtual Hosts in Apache
By default, Apache’s Virtual Hosts feature is disabled in XAMPP. To enable it:
- Open the Apache configuration file:
E:\xampp8.2\apache\conf\httpd.conf
- Search for the following line:
#Include conf/extra/httpd-vhosts.conf
- Remove the
#at the beginning to uncomment the line:
Include conf/extra/httpd-vhosts.conf
- Save and close the file.
Step 2: Create a Virtual Host Configuration
Next, we define the custom domain in Apache’s virtual host configuration file.
- Open the Virtual Hosts file:
E:\xampp8.2\apache\conf\extra\httpd-vhosts.conf
- Add the following code at the bottom of the file to create a virtual host for your site:
<VirtualHost *:80>
DocumentRoot "E:/xampp8.2/htdocs"
ServerName localhost
<Directory "E:/xampp8.2/htdocs">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "E:/xampp8.2/htdocs/mywebsite"
ServerName mywebsite.local
ServerAlias www.mywebsite.local
ErrorLog "logs/mywebsite-error.log"
CustomLog "logs/mywebsite-access.log" common
<Directory "E:/xampp8.2/htdocs/mywebsite">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
- Save and close the file.
Step 3: Update the Windows Hosts File
To access thecreativecoders.local, we need to map it in the Windows hosts file.
- Open Notepad as Administrator.
- Open this file:
C:\Windows\System32\drivers\etc\hosts
- Add this line at the bottom:
127.0.0.1 thecreativecoders.local
- Save and close the file.
Step 4: Restart Apache and Test the Virtual Host
- Open XAMPP Control Panel.
- Click Stop next to Apache, then Start again.
- Open a browser and go to:
http://thecreativecoders.local
- If everything is configured correctly, you should see the contents of your website folder.
Conclusion
Setting up Virtual Hosts in XAMPP makes local development much easier. Instead of navigating to localhost/, you can simply type thecreativecoders in the browser.thecreativecoders.local
By following these steps, you can create multiple sites locally, streamline your workflow, and prepare for live deployment more efficiently.