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

部署Laravel 8应用至Hostinger虚拟主机时出现HTTP 500错误与白屏问题

Troubleshooting Laravel 500 White Screen on Virtual Host Deployment

Hey, I feel your pain—500 errors with no feedback are the worst, especially after you’ve gone through all the standard steps. Let’s break down some additional checks to get your Laravel app up and running:

1. Dig Into Error Logs (Critical!)

You can’t fix what you can’t see. First, check two sets of logs:

  • Laravel Logs: Look in your root project’s storage/logs/ directory for recent .log files. These will show Laravel-specific errors like database connection issues or missing dependencies.
  • Server Error Logs: Most virtual hosts (like cPanel) have an "Error Logs" tool in the control panel. This will catch server-level problems, like PHP version mismatches or permission denials that Laravel can’t log.

2. Fix Directory Permissions

Laravel needs write access to two key directories to function properly. On most virtual hosts, run these commands via SSH (or adjust permissions via FTP):

# Set correct permissions for storage and bootstrap/cache
chmod -R 755 storage bootstrap/cache
# Ensure the web server can access these files (adjust group if needed)
chown -R your_username:www-data storage bootstrap/cache

If you don’t know the web server group, www-data is standard for Apache, and nginx for Nginx—check your host’s docs if unsure.

3. Verify index.php Paths Again

Since you split the project between root and public_html, double-check that your public_html/index.php points correctly to the root project files. It should look like this:

// Path to vendor autoload (one level up from public_html to root)
require __DIR__.'/../vendor/autoload.php';
// Path to bootstrap app file
$app = require_once __DIR__.'/../bootstrap/app.php';

If your root project is in a subfolder (not the direct parent of public_html), adjust the ../ to match the actual relative path.

4. Check .htaccess Configuration

A messed-up .htaccess in public_html can cause silent 500 errors. Make sure you’re using Laravel’s default .htaccess for Apache:

<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 your virtual host allows AllowOverride All—if not, ask your host to enable it, as this is required for Laravel’s rewrite rules to work.

5. Confirm PHP Version Compatibility

Laravel is picky about PHP versions. For example:

  • Laravel 10 requires PHP 8.1+
  • Laravel 9 needs PHP 8.0+
  • Laravel 8 supports PHP 7.3–8.1

Check your host’s PHP version via the control panel (e.g., cPanel’s "Select PHP Version") or create a phpinfo.php file in public_html with:

<?php phpinfo(); ?>

Access it in your browser to verify the version matches your project’s requirements.

6. Double-Check .env for Typos & Debug Mode

Even small typos in .env can break everything. Look closely at:

  • Database credentials (DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD)
  • APP_URL (make sure it matches your domain)
  • Temporarily set APP_DEBUG=true (don’t forget to set it back to false in production!)—this will show detailed error messages instead of a white screen, which is a game-changer for troubleshooting.

If none of these steps work, reach out to your virtual host’s support—some hosts have strict security rules or custom configurations that block Laravel’s default setup.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 17:02:28