You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Ubuntu 16.04中配置Vhost遇阻求助(Laravel+XAMPP环境)

Troubleshooting Laravel Virtual Host Setup with XAMPP on Ubuntu 16.04

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.conf in a text editor (use sudo nano /opt/lampp/etc/httpd.conf for 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:30:36