Hosts File Setup for Laravel/WordPress Local Development
Complete guide to configuring hosts files for Laravel Valet, Herd, and WordPress local development. Learn custom domains (.test, .local), multisite configurations, and best practices.
Locahl Team
Table of Contents
- Understanding Local Development Environments
- Laravel Valet
- Laravel Herd
- WordPress Local Development
- Laravel Valet Hosts File Configuration
- Automatic .test Domain Setup
- Basic Valet Setup
- Custom Domains with Valet
- Multiple Projects Organization
- Valet with HTTPS
- Laravel Herd Configuration
- Automatic .test Handling
- Herd Custom Domains
- Herd Site Management
- WordPress Local Development Setup
- WordPress with Valet/Herd
- WordPress with MAMP
- WordPress Multisite Configuration
- WordPress Multisite with Valet
- WordPress with Local by Flywheel
- Advanced Configuration Scenarios
- Multiple Laravel Projects
- API + Frontend Separation
- Microservices Architecture
- Staging/Production Domain Testing
- Choosing the Right TLD
- .test (Recommended)
- .local
- .localhost
- .dev
- Organizing Your Hosts File
- Project-Based Organization
- Environment-Based Organization
- Client-Based Organization
- HTTPS Configuration
- Valet HTTPS
- Herd HTTPS
- Manual HTTPS Setup
- WordPress HTTPS
- Common Laravel Development Patterns
- Laravel + Vue/React Frontend
- Laravel Multi-Tenant
- Laravel API + Mobile App Testing
- WordPress-Specific Scenarios
- WordPress + WooCommerce
- WordPress Multisite with Domain Mapping
- WordPress Headless (Headless CMS)
- Troubleshooting Common Issues
- Issue: .test Domain Not Resolving
- Issue: .local Domain Slow
- Issue: Valet Sites Not Working
- Issue: WordPress Multisite Subdomains Not Working
- Issue: HTTPS Certificate Errors
- Best Practices
- 1. Use .test Domains
- 2. Organize by Project
- 3. Document Custom Configurations
- 4. Use Version Control
- 5. Regular Cleanup
- 6. Leverage Valet/Herd Features
- Integration with Development Tools
- Laravel Artisan
- WordPress WP-CLI
- Database Access
- Git Workflow
- Conclusion
Laravel and WordPress developers rely on local development environments to build and test applications efficiently. Whether you're using Laravel Valet, Herd, MAMP, or custom setups, proper hosts file configuration is essential for creating realistic local development environments with custom domains. This comprehensive guide covers everything you need to know about configuring hosts files for Laravel and WordPress local development on macOS.
Understanding Local Development Environments
Laravel Valet
Laravel Valet is a lightweight development environment for macOS that uses Nginx and Dnsmasq to automatically serve Laravel and other PHP applications. Valet automatically configures .test domains, making it incredibly easy to work with multiple projects.
Laravel Herd
Laravel Herd is the modern successor to Valet, providing a GUI application for managing local PHP development. Like Valet, Herd handles .test domains automatically through dnsmasq.
WordPress Local Development
WordPress developers often use:
- Local by Flywheel
- MAMP/XAMPP
- Laravel Valet/Herd
- Docker
- Custom server setups
Each requires different hosts file configurations.
Simplify your hosts file management
Locahl lets you manage your hosts file visually, without touching the terminal. Automatic DNS flush, multiple environments, and backups included.
Laravel Valet Hosts File Configuration
Automatic .test Domain Setup
Valet automatically handles .test domains through dnsmasq, so you typically don't need manual hosts file edits. However, understanding how it works helps troubleshoot issues.
How Valet Works:
# Valet installs dnsmasq and configures it
valet install
# This creates:
# /usr/local/etc/dnsmasq.conf
# address=/.test/127.0.0.1
# And resolver:
# /etc/resolver/test
# nameserver 127.0.0.1Any *.test domain automatically resolves to 127.0.0.1.
Basic Valet Setup
# Install Valet
composer global require laravel/valet
valet install
# Park a directory
cd ~/Sites
valet park
# Or link a specific project
cd ~/Sites/my-laravel-app
valet link myappNow access at http://myapp.test - no hosts file editing needed!
Custom Domains with Valet
If you need custom domains (not .test), add to hosts file:
# /etc/hosts
127.0.0.1 myapp.local
127.0.0.1 api.myapp.localThen configure Valet:
valet link myapp --domain=myapp.localMultiple Projects Organization
Organize your hosts file for multiple Valet projects:
# /etc/hosts
# ===================
# LARAVEL VALET PROJECTS
# ===================
# Note: .test domains handled automatically by Valet
# Only add non-.test domains here
# Custom domain projects
127.0.0.1 client-project.local
127.0.0.1 api.client-project.localValet with HTTPS
Valet makes HTTPS trivial:
cd ~/Sites/myapp
valet secure myappAccess at https://myapp.test - Valet handles certificates automatically via mkcert.
Laravel Herd Configuration
Automatic .test Handling
Herd, like Valet, automatically handles .test domains. The GUI makes it even easier:
1. Install Herd 2. Add your project directory 3. Access via projectname.test
No hosts file configuration needed for standard .test domains.
Herd Custom Domains
For custom domains with Herd:
# /etc/hosts
127.0.0.1 myapp.localThen configure in Herd GUI or via CLI:
herd link myapp --domain=myapp.localHerd Site Management
Herd provides excellent site management:
# List all sites
herd list
# Link a site
herd link myapp
# Secure with HTTPS
herd secure myapp
# Unlink
herd unlink myappWordPress Local Development Setup
WordPress with Valet/Herd
WordPress works great with Valet and Herd:
# Create WordPress site
cd ~/Sites
mkdir my-wordpress-site
cd my-wordpress-site
# Download WordPress
wp core download
# Link with Valet
valet link wp-site
# Or use Herd GUIAccess at http://wp-site.test - automatic!
WordPress with MAMP
MAMP requires manual hosts file configuration:
# /etc/hosts
127.0.0.1 wordpress.local
127.0.0.1 mywp.localThen configure MAMP: 1. Set document root to WordPress directory 2. Configure Apache virtual host 3. Set ServerName to wordpress.local
WordPress Multisite Configuration
WordPress Multisite requires careful hosts file setup:
Subdomain Multisite:
# /etc/hosts
127.0.0.1 multisite.test
127.0.0.1 site1.multisite.test
127.0.0.1 site2.multisite.test
127.0.0.1 admin.multisite.testSubdirectory Multisite (simpler):
# /etc/hosts
127.0.0.1 multisite.test
# Subdirectories handled automatically: multisite.test/site1, multisite.test/site2WordPress Multisite with Valet
Valet handles WordPress Multisite beautifully:
# Link main site
valet link multisite
# Valet automatically serves subdomains
# site1.multisite.test works automatically!Configure WordPress: 1. Enable Multisite in wp-config.php 2. Choose subdomain or subdirectory 3. Add sites in Network Admin 4. Access via site1.multisite.test, site2.multisite.test, etc.
WordPress with Local by Flywheel
Local by Flywheel handles hosts file automatically, but you can customize:
# Local creates entries like:
127.0.0.1 mysite.localTo use .test instead, configure in Local settings or manually edit hosts file.
Advanced Configuration Scenarios
Multiple Laravel Projects
Organize multiple Laravel projects:
# /etc/hosts
# ===================
# LARAVEL PROJECTS
# ===================
# Project 1 - E-commerce
# api.shop.test (handled by Valet automatically)
# admin.shop.test (handled by Valet automatically)
# Project 2 - Blog Platform
# blog.test (handled by Valet automatically)
# Project 3 - Custom domain
127.0.0.1 legacy-app.local
127.0.0.1 api.legacy-app.localAPI + Frontend Separation
Separate API and frontend:
# /etc/hosts
# Laravel API
# api.myapp.test (Valet handles automatically)
# Frontend (React/Vue)
127.0.0.1 myapp.test
# Or use Valet: valet link frontend --domain=myapp.testFrontend at myapp.test, API at api.myapp.test.
Microservices Architecture
For microservices with Laravel:
# /etc/hosts
# Main Application
# app.test (Valet)
# User Service
# users.api.test (Valet)
# Payment Service
# payments.api.test (Valet)
# Notification Service
# notifications.api.test (Valet)Each service in its own Valet-linked directory.
Staging/Production Domain Testing
Test with production-like domains:
# /etc/hosts
# Local development with production domain
127.0.0.1 www.myapp.com
127.0.0.1 api.myapp.comUseful for testing domain-specific configurations, cookies, and SSL.
Choosing the Right TLD
.test (Recommended)
Pros:
- Reserved by IETF
- No conflicts with real domains
- Automatic with Valet/Herd
- Fast resolution
Cons:
- None for local development
Best for: Laravel Valet, Herd, general local development
.local
Pros:
- Common convention
- Easy to remember
Cons:
- Conflicts with macOS Bonjour
- Can be slow
- Requires both IPv4 and IPv6 entries
Best for: Legacy setups, when .test unavailable
Configuration:
# /etc/hosts - Must include both!
127.0.0.1 myapp.local
::1 myapp.local.localhost
Pros:
- Always resolves to localhost
- No DNS queries
- Very fast
Cons:
- Less common
- Some tools may not recognize
Best for: Simple setups, when you want guaranteed local resolution
.dev
Pros:
- Familiar
- Short
Cons:
- Real TLD (owned by Google)
- Requires HTTPS
- Not recommended for local dev
Avoid: Use .test instead
Organizing Your Hosts File
Project-Based Organization
# /etc/hosts
# ===================
# LARAVEL: E-commerce Platform
# ===================
# shop.test (Valet handles)
# api.shop.test (Valet handles)
# ===================
# WORDPRESS: Client Sites
# ===================
127.0.0.1 client1.local
127.0.0.1 client2.local
# ===================
# PERSONAL PROJECTS
# ===================
# blog.test (Valet handles)Environment-Based Organization
# ===================
# DEVELOPMENT
# ===================
127.0.0.1 dev.myapp.local
# ===================
# STAGING (Local)
# ===================
127.0.0.1 staging.myapp.localClient-Based Organization
# ===================
# CLIENT: Acme Corp
# ===================
127.0.0.1 acme.local
127.0.0.1 www.acme.local
127.0.0.1 admin.acme.local
# ===================
# CLIENT: Beta Inc
# ===================
127.0.0.1 beta.local
127.0.0.1 api.beta.localHTTPS Configuration
Valet HTTPS
Valet makes HTTPS automatic:
cd ~/Sites/myapp
valet secure myappAccess at https://myapp.test. Valet uses mkcert for trusted certificates.
Herd HTTPS
Herd also handles HTTPS automatically via GUI or CLI:
herd secure myappManual HTTPS Setup
For custom setups, use mkcert:
# Install mkcert
brew install mkcert
mkcert -install
# Create certificate
cd ~/Sites/myapp
mkcert myapp.local "*.myapp.local"Then configure your web server (Apache/Nginx) to use the certificates.
WordPress HTTPS
For WordPress with HTTPS:
# With Valet
valet secure wp-site
# Update WordPress URLs
wp option update home 'https://wp-site.test'
wp option update siteurl 'https://wp-site.test'Common Laravel Development Patterns
Laravel + Vue/React Frontend
# Backend API
cd ~/Sites/myapp-api
valet link api
# Frontend
cd ~/Sites/myapp-frontend
valet link app
# Access:
# Backend: http://api.test
# Frontend: http://app.testFrontend calls API at http://api.test/api/....
Laravel Multi-Tenant
For multi-tenant applications:
# /etc/hosts
# Tenant 1
127.0.0.1 tenant1.myapp.test
# Tenant 2
127.0.0.1 tenant2.myapp.testConfigure Laravel to detect tenant from domain.
Laravel API + Mobile App Testing
# /etc/hosts
# API accessible from mobile device on same network
# Use Mac's local IP instead of 127.0.0.1
192.168.1.100 api.myapp.testMobile device can access API at http://api.myapp.test when on same WiFi.
WordPress-Specific Scenarios
WordPress + WooCommerce
# Standard setup
valet link shop
# Access at shop.testTest payment gateways, shipping, etc. locally.
WordPress Multisite with Domain Mapping
# /etc/hosts
127.0.0.1 site1.com
127.0.0.1 site2.com
127.0.0.1 multisite.testConfigure WordPress Multisite Domain Mapping plugin to map custom domains.
WordPress Headless (Headless CMS)
# WordPress Backend
valet link wp-api
# Frontend (Next.js, etc.)
valet link frontend
# Access:
# WordPress: http://wp-api.test/wp-json
# Frontend: http://frontend.testTroubleshooting Common Issues
Issue: .test Domain Not Resolving
Symptoms: Domain doesn't work, connection refused.
Solutions: 1. Check Valet/Herd is running: valet status or check Herd GUI 2. Verify dnsmasq: brew services list | grep dnsmasq 3. Check resolver: cat /etc/resolver/test 4. Restart Valet: valet restart 5. Flush DNS: sudo dscacheutil -flushcache
Issue: .local Domain Slow
Symptoms: .local domains take seconds to load.
Causes: Bonjour/mDNS conflicts.
Solutions: 1. Use .test instead 2. Add IPv6 entry: ::1 myapp.local 3. Disable Bonjour (not recommended)
Issue: Valet Sites Not Working
Symptoms: Valet-linked sites return 404 or connection refused.
Solutions: 1. Check site is linked: valet links 2. Verify directory exists and has index.php 3. Check Nginx config: valet paths 4. Restart Valet: valet restart 5. Check PHP version: valet php --version
Issue: WordPress Multisite Subdomains Not Working
Symptoms: Subdomains return 404.
Solutions: 1. Verify hosts file has all subdomains 2. Check WordPress Multisite configuration 3. Ensure Valet/Herd handles wildcard subdomains 4. Verify .htaccess or Nginx configuration 5. Clear WordPress cache
Issue: HTTPS Certificate Errors
Symptoms: Browser shows certificate warnings.
Solutions: 1. Re-secure with Valet: valet secure myapp 2. Check mkcert is installed: mkcert -install 3. Verify certificate exists: ls ~/.config/valet/Certificates 4. Clear browser cache 5. Check system date/time is correct
Best Practices
1. Use .test Domains
Always prefer .test for local development:
- Automatic with Valet/Herd
- No conflicts
- Fast resolution
- Industry standard
2. Organize by Project
Keep hosts file organized:
# Clear sections
# Comments for context
# Group related domains3. Document Custom Configurations
Document non-standard setups:
# Custom domain for legacy app
# Requires manual Nginx config
127.0.0.1 legacy.local4. Use Version Control
For team projects, include hosts file template:
# hosts.example
127.0.0.1 api.myapp.test
127.0.0.1 admin.myapp.test5. Regular Cleanup
Remove unused entries:
- Archive old projects
- Remove test configurations
- Keep file manageable
6. Leverage Valet/Herd Features
Use built-in features:
- Automatic .test handling
- HTTPS with one command
- Easy site management
- PHP version switching
Integration with Development Tools
Laravel Artisan
# Access via custom domain
php artisan serve --host=myapp.test --port=8000WordPress WP-CLI
# Configure WordPress URLs
wp option update home 'http://wp-site.test'
wp option update siteurl 'http://wp-site.test'
# Search-replace old URLs
wp search-replace 'http://localhost' 'http://wp-site.test'Database Access
# Laravel
# Database: myapp
# Host: 127.0.0.1 (or localhost)
# WordPress
# Same - use 127.0.0.1 or localhostGit Workflow
# .gitignore
# Ignore local environment files
.env
/public/hot
/storage/*.keyInclude hosts file template in repository for team.
Conclusion
Proper hosts file configuration is essential for productive Laravel and WordPress local development. Whether you're using Laravel Valet, Herd, MAMP, or custom setups, understanding how to configure hosts files enables you to:
- Create realistic local development environments
- Test with production-like domains
- Manage multiple projects efficiently
- Configure WordPress Multisite correctly
- Set up complex architectures (APIs, microservices, multi-tenant)
Remember to use .test domains when possible (especially with Valet/Herd), organize your hosts file clearly, and leverage tools like Locahl (€9.99) to manage configurations across projects and team members. With proper setup, local development becomes seamless and efficient.
For Laravel and WordPress developers, Locahl simplifies hosts file management, making it easy to switch between projects, share configurations with teammates, and maintain organized local development environments. Try Locahl today at €9.99 and streamline your development workflow.
Ready to simplify your workflow?
Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.
- Intuitive visual interface
- Automatic DNS flush
- Multi-environment management
- Automatic backups
- JSON Import/Export
Reader Reviews
"Perfect guide for Laravel Valet users! The multisite WordPress section was exactly what I needed. Clear, practical examples throughout."
February 6, 2026
"Finally understand how to properly configure .test domains with Herd. The hosts file organization tips saved me so much time."
February 6, 2026
"Great comprehensive guide. Would have liked more on Laravel Sail integration, but the Valet and Herd sections are excellent."
February 6, 2026
Frequently Asked Questions
What TLD should I use for Laravel Valet local domains?
Use .test domains with Laravel Valet. Valet automatically configures .test domains, and .test is reserved by IETF, avoiding conflicts with real domains.
How do I set up custom domains for WordPress multisite?
Add each site domain to your hosts file pointing to 127.0.0.1, configure WordPress multisite with domain mapping, and ensure your local server (Valet/Herd) handles the domains correctly.
Do I need to edit hosts file with Laravel Herd?
Herd automatically handles .test domains via dnsmasq, so you typically don't need manual hosts file edits. However, for custom domains or .local setups, you may need hosts file entries.
Why is my .local domain slow on Mac?
.local domains use macOS Bonjour/mDNS which can cause delays. Use .test or .localhost instead, or ensure both IPv4 and IPv6 entries exist in your hosts file.
How do I test HTTPS locally with Laravel Valet?
Run `valet secure yoursite.test` to enable HTTPS. Valet uses mkcert automatically to create trusted certificates. No manual hosts file changes needed for HTTPS.
Can I use custom domains instead of .test with Valet?
Yes, but you'll need to manually add entries to your hosts file. Valet's automatic .test handling won't work, so you'll need to configure your server manually for custom domains.
Related Articles
Using Hosts Files for Docker Development on Mac
Learn how to configure hosts files for Docker, docker-compose, and container networking. Map container services to local domains and streamline your Docker development workflow.
Locahl Team
Edit the hosts file on Mac: Terminal vs GUI (2026)
How to edit /etc/hosts on macOS without errors? Terminal (sudo nano) vs GUI comparison. Fix permission denied and DNS cache issues in 2 minutes.
Locahl Team
Hosts file: definition, location, and syntax (2026 guide)
Master the hosts file in 5 minutes: location on Mac/Windows/Linux, syntax, use cases (local dev, ad blocking) and common mistakes to avoid. Updated January 2026.
Locahl Team