If you're building Laravel applications locally, you've probably relied on php artisan serve to get things running. It works, but it's a shortcut — not a setup. Configuring virtual hosts through XAMPP gives you a proper local environment that mirrors how your app will behave in production, complete with clean custom URLs like laravel.local instead of the clunky localhost/myproject/public.
This guide walks you through the full setup on Windows 10 in four straightforward steps.
Why Bother with Virtual Hosts?
Two reasons: cleanliness and accuracy.
With virtual hosts, each project gets its own domain-style URL. You stop wrestling with subdirectory paths and Laravel's public folder nuances — the virtual host points directly to it. More importantly, your local setup starts to resemble a real server, which means fewer surprises when you deploy.
Step 1: Open the Virtual Hosts Configuration File
Navigate to your XAMPP installation directory and open the Apache extras folder:
C:/xampp/apache/conf/extra/
Find the file named httpd-vhosts.conf and open it in any text editor — VSCode, Notepad, whatever you prefer.
Step 2: Add a Virtual Host Entry
Scroll to the bottom of the file and append the following block:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/laravel/public"
ServerName laravel.local
ServerAlias www.laravel.local
</VirtualHost>
A quick breakdown of each directive:
-
DocumentRoot — the path to your project's
publicfolder. Adjust this to match where your Laravel project lives. - ServerName — the local domain you'll use in the browser.
-
ServerAlias — optional, but useful if you want
www.laravel.localto resolve to the same project.
Step 3: Update the Windows Hosts File
Windows needs to know that laravel.local should resolve to your local machine, not the internet.
- Press
Windows + R, then run:
notepad C:\Windows\System32\drivers\etc\hosts
- Add this line at the bottom of the file:
127.0.0.1 laravel.local
- Save the file. If Windows blocks the save, close Notepad, reopen it as Administrator, and try again.
Step 4: Restart Apache and Verify
Open the XAMPP Control Panel and restart the Apache service. Then visit http://laravel.local in your browser. Your Laravel app should load directly — no subdirectory path, no public folder in the URL.
A Few Extras Worth Knowing
Port conflicts: If port 80 is already in use by another process (IIS, for example), change *:80 to *:8080 in your virtual host config. You'll then access the site at laravel.local:8080.
Multiple projects: Repeat steps 2 and 3 for each project, using a unique DocumentRoot and ServerName for each. There's no limit to how many virtual hosts you can define.
Prefer a Simpler Path?
If you'd rather skip manual configuration altogether, Laravel Herd is worth a look. It's a dedicated local development environment for Laravel on Windows and macOS that handles virtual hosts, PHP versions, and SSL automatically — no Apache config files required. The one current gap: it doesn't include a bundled database server like MariaDB, so you may still need XAMPP or a standalone database tool alongside it.
Once this is set up, your local environment is cleaner, more predictable, and far closer to what you'll run in production. That alignment pays off the moment you start debugging environment-specific issues — because there will be far fewer of them.
Top comments (0)