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
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>
- 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.
- Press
Windows + R
, typenotepad C:\Windows\System32\drivers\etc\hosts
, and hit Enter. - Add this line to the end of the file:
127.0.0.1 laravel.local
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:
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.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.
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! 🚀
Top comments (0)