Configure Virtual Hosts on XAMPP for Laravel
| |

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

Reading Time: 3 minutes

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, and 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!


Configure Virtual Hosts on XAMPP for Laravel

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

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>
Code language: HTML, XML (xml)
  • 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
Code language: CSS (css)

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:

  1. Simplify Your Laravel Workflow with Git Hooks: Automate Migrations and Caching
    Save time by automating those tedious migrations and caching tasks every time you pull or merge code.
  2. Mastering Laravel PHPUnit.xml: The Ultimate Guide to Overcoming Pitfalls
    Dive into the world of Laravel testing with a complete breakdown of PHPUnit.xml configurations.
  3. Fix Vite Manifest Not Found Issue in Laravel: A Practical Guide – 3 Proven Solutions
    Tackle those pesky Vite manifest issues with proven fixes tailored for Laravel projects.

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! 🚀

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

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox.

We don’t spam! Read our privacy policy for more info.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.