在Ubuntu 16.04中配置Vhost遇阻求助(Laravel+XAMPP环境)
Let’s walk through fixing your virtual host issue— I’ve dealt with this exact scenario before, so let’s break down the common gaps in your setup:
1. Verify Your Virtual Host File is Loaded
First, make sure XAMPP is actually reading your vhost configuration:
- Open
/opt/lampp/etc/httpd.confin a text editor (usesudo nano /opt/lampp/etc/httpd.conffor quick access) - Look for the line:
#Include etc/extra/httpd-vhosts.conf - Remove the
#to uncomment it, save the file, and close it. This tells Apache to load your virtual host settings.
2. Fix Your Virtual Host Configuration
Your current config is missing critical directives that let Laravel’s .htaccess work properly. Update your entry in /opt/lampp/etc/extra/httpd-vhosts.conf to this:
<VirtualHost *:80> DocumentRoot "/opt/lampp/htdocs/basicwebsite/public" ServerName mywebsite.dev ServerAlias www.mywebsite.dev # Optional, for www subdomain # Critical for Laravel's routing <Directory "/opt/lampp/htdocs/basicwebsite/public"> Options Indexes FollowSymLinks MultiViews AllowOverride All # Lets .htaccess override default settings Require all granted </Directory> # Optional but helpful for debugging ErrorLog "/opt/lampp/logs/mywebsite-error_log" CustomLog "/opt/lampp/logs/mywebsite-access_log" common </VirtualHost>
3. Update Your System Hosts File
Ubuntu needs to know where to route mywebsite.dev— add it to your hosts file:
- Run
sudo nano /etc/hosts - Add these lines at the bottom:
127.0.0.1 mywebsite.dev ::1 mywebsite.dev # For IPv6 support - Save and exit (Ctrl+O, then Ctrl+X in nano)
4. Fix Directory Permissions
Laravel needs proper access to its files to run. Run these commands to set correct permissions:
sudo chmod -R 755 /opt/lampp/htdocs/basicwebsite/public sudo chown -R nobody:nogroup /opt/lampp/htdocs/basicwebsite # XAMPP's Apache runs as nobody by default
Also, make sure the storage and bootstrap/cache directories in your Laravel root are writable:
sudo chmod -R 775 /opt/lampp/htdocs/basicwebsite/storage sudo chmod -R 775 /opt/lampp/htdocs/basicwebsite/bootstrap/cache
5. Restart XAMPP and Test
- Restart Apache (or the entire XAMPP stack) with:
sudo /opt/lampp/lampp restart apache - Clear your browser’s cache, then visit
http://mywebsite.dev— it should load your Laravel app now.
Quick Note on .dev Domains
Heads up: The .dev top-level domain is now owned by Google and forces HTTPS by default, which might cause unexpected issues locally. For a smoother experience, consider switching to .test or .local (e.g., mywebsite.test) instead— just update both your vhost config and hosts file to match.
内容的提问来源于stack exchange,提问作者Vasim Shaikh

