
๐ฅ๏ธ How to Create a Virtual Host in XAMPP (Windows)
Want to access your local project via http://myproject.local
instead of http://localhost/myproject
?
Thatโs where Virtual Hosts come in!
Hereโs a step-by-step guide to setting up a virtual host in XAMPP:
๐ ๏ธ Step 1: Open Apache Config File
Go to:C:\xampp\apache\conf\extra\httpd-vhosts.conf
Add this block at the bottom:
<VirtualHost *:80>
ServerAdmin webmaster@myproject.local
DocumentRoot "C:/xampp/htdocs/myproject"
ServerName myproject.local
ErrorLog "logs/myproject-error.log"
CustomLog "logs/myproject-access.log" common
</VirtualHost>
โ
Replace "myproject"
with your folder name.
๐ Step 2: Edit the Windows Hosts File
Open this file in Notepad (as administrator):C:\Windows\System32\drivers\etc\hosts
Add this line:
127.0.0.1 myproject.local
๐ Important: Save it as administrator, or it wonโt update.
๐งฉ Step 3: Enable Virtual Hosts in Apache
Go to:C:\xampp\apache\conf\httpd.conf
๐ Search for this line:
#Include conf/extra/httpd-vhosts.conf
โ
Uncomment it by removing #
:
Include conf/extra/httpd-vhosts.conf
๐ Step 4: Restart Apache
Open the XAMPP control panel and click Stop, then Start next to Apache.
๐ Now open your browser and visit:http://myproject.local
โ It should load your project!
๐ก Bonus Tip
You can create multiple virtual hosts like:
client1.local
ecommerce.local
portfolio.local
Just repeat the same steps and add more <VirtualHost>
blocks!
๐ Need Help with XAMPP, PHP, or Local Dev?
๐ง Reach out to sktiwari.com for custom setups, internships, and full-stack development solutions.