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

Laravel主机部署后无法访问public目录问题求助

Troubleshooting Laravel 500 Error When Accessing public/index.php on Host

Hey there, let's work through this frustrating 500 error you're hitting on your host—since everything works locally, we know it's an environment-specific issue. Let's break down the most likely fixes step by step:

1. Fix File Permissions First

Laravel requires specific write permissions for its storage and bootstrap/cache directories, and incorrect permissions are a super common cause of 500 errors on shared hosts. Try running these commands via SSH (or use your host's file manager to adjust permissions):

  • Set directory permissions: chmod -R 755 storage bootstrap/cache
  • Set file ownership (if your host uses www-data as the web server user): chown -R www-data:www-data storage bootstrap/cache

Also double-check that your public directory and its index.php file have read permissions (at least 644 for files, 755 for directories).

2. Adjust Your Root .htaccess Configuration

When you copied the .htaccess from the public directory to the root, you need to tweak it to work from the root level instead of the public folder. Replace your root .htaccess with this:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Also confirm that your host has mod_rewrite enabled—you can check this by creating a phpinfo.php file with <?php phpinfo(); ?> and searching for "mod_rewrite" in the output. If it's missing, reach out to your host to enable it.

3. Verify the Index.php Path in Root

Your root index.php (renamed from server.php) should have this line to load the public index:

require __DIR__.'/public/index.php';

Since you confirmed the path /home/ebsprint/public_html/enigma-crm/public/index.php is correct, this should be fine—but some hosts have open_basedir restrictions that block access to certain directories. Check your host's PHP settings (via phpinfo or your control panel) to ensure the public directory is within the allowed paths, or contact your host support to confirm.

4. Check Server Error Logs for Exact Details

A 500 error is generic—your server's error logs will tell you the real issue (like a missing extension, syntax error, or permission denied message). Look for:

  • Apache: error.log (usually in /var/log/apache2/ or via your host's control panel, e.g., cPanel's "Error Logs" tool)
  • Nginx: error.log (typically in /var/log/nginx/)

This is the fastest way to pinpoint the root cause if the above steps don't fix it.

5. Validate Environment Configuration

Double-check your .env file in the root:

  • Ensure APP_DEBUG=true temporarily (turn it off after troubleshooting!) to see if detailed errors are displayed (some hosts disable this by default, so logs are still better)
  • Confirm APP_URL matches your host's domain
  • Set .env file permissions to 644 (too open permissions can trigger security-related errors)

内容的提问来源于stack exchange,提问作者user5405873

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 06:40:03