DEV Community

Cover image for How to Configure Virtual Hosts on XAMPP for Laravel on Windows 10
Shakil Alam
Shakil Alam

Posted on

How to Configure Virtual Hosts on XAMPP for Laravel on Windows 10

Picture this: you're a budding Laravel developer, running php artisan serve like it’s your morning coffee ritual. It gets the job done, sure—but what if you could take your local environment from “just enough” to “pro-level”? Setting up virtual hosts with XAMPP is like upgrading your kitchen from a hotplate to a full chef’s suite. It's neat, professional, and makes transitioning to live servers a breeze.

In this guide, I’ll show you exactly how to configure virtual hosts on XAMPP for Windows 10. And trust me—it’s simpler than it sounds. Ready? Let’s roll!


Why Virtual Hosts Matter

Think of virtual hosts as your local web magician. They let you create multiple domain-like environments, making it easier to organize and test projects. This way, instead of typing localhost/myproject a hundred times a day, you can use laravel.local or any custom domain you fancy.

But here’s the best part: you’ll no longer need to deal with Laravel’s public folder mess. The virtual host serves the app directly from the public directory, so you can focus on what truly matters—building awesome features instead of worrying about URL structures.


How to Configure Virtual Hosts on XAMPP for Laravel on Windows 10

Let’s break this down into a series of simple steps.

Step 1: Find the Right File

Navigate to your XAMPP installation directory. Usually, it’s here:

C:/xampp/apache/conf/extra
Enter fullscreen mode Exit fullscreen mode

Inside the extra folder, locate the httpd-vhosts.conf file. This is where the magic begins. Open it using your favorite text editor (mine’s VSCode, but Notepad works fine too).


Step 2: Add Your Virtual Host Configuration

Scroll to the end of the file and add this snippet:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/laravel/public"
    ServerName laravel.local
    ServerAlias www.laravel.local
</VirtualHost>
Enter fullscreen mode Exit fullscreen mode
  • DocumentRoot: Points to the directory where your project lives. In this case, we’re targeting Laravel’s public folder.
  • ServerName: The URL for your local site (e.g., laravel.local).
  • ServerAlias: Optional, but handy if you want multiple domains pointing to the same project.

Step 3: Tweak Your Hosts File

Next, we need to tell Windows where to look for your custom domain.

  1. Press Windows + R, type notepad C:\Windows\System32\drivers\etc\hosts, and hit Enter.
  2. Add this line to the end of the file:
   127.0.0.1 laravel.local
Enter fullscreen mode Exit fullscreen mode

You’ll likely need admin permissions to save the changes. If it complains, just run Notepad as an administrator and try again.


Step 4: Restart XAMPP and Test

Finally, restart Apache in the XAMPP control panel. Now open your browser, type laravel.local, and hit Enter. Voilà! Your virtual host is live.


Pro Tips for the Win

  • Change the Port: If port 80 is already in use, modify the <VirtualHost *:80> line to something like <VirtualHost *:8080>. Don’t forget to include the port number in your browser: laravel.local:8080.
  • More Projects?: Just repeat these steps for each one, updating the DocumentRoot and ServerName accordingly.

Leveling Up with Laravel Herd

If you’re loving the idea of seamless local development but wish there was an even easier way, check out Laravel Herd. It’s a blazing-fast, zero-hassle local development tool for Laravel that skips all the configuration drama. Herd does all the heavy lifting for you, so you can spend less time configuring and more time coding. I wish it also had a MariaDB or SQL server.


Learn More About Laravel

Want to supercharge your Laravel workflow? Check out these related posts:


Wrapping Up

And there you have it—a professional-grade local environment for your Laravel projects. No more generic localhost URLs, no more chaos. Just clean, organized development bliss.

Got stuck? Found a better way? Let’s hash it out in the comments below. Your feedback makes this a community, not just a tutorial.

Happy coding, my friend! 🚀

Top comments (0)