How to Create a Virtual Host in XAMPP

Virtual Host in XAMPP

๐Ÿ–ฅ๏ธ 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.