500 Errors & Debugging
How to diagnose and fix 500 Internal Server Errors.
Step 1: Check the Log
The most important step. Laravel logs all errors to:
tail -100 storage/logs/laravel.log
This will show you the exact error message, file, and line number.
Step 2: Enable Debug Mode (Temporarily!)
APP_DEBUG=true
Refresh the page -- you'll see a detailed error page with:
- Error message
- Stack trace
- Request details
- Environment info
警告
Set APP_DEBUG=false immediately after debugging!
Common 500 Errors
"The stream or file could not be opened"
Cause: Storage permissions issue.
sudo chmod -R 775 storage bootstrap/cache
sudo chown -R www-data:www-data storage bootstrap/cache
"No application encryption key has been specified"
Cause: Missing or invalid APP_KEY.
php artisan key:generate
"SQLSTATE[HY000] Connection refused"
Cause: データベース connection failed.
Check .env database settings and ensure MySQL is running.
"Class 'X' not found"
Cause: Missing Composer dependencies.
composer install --no-dev --optimize-autoloader
php artisan config:clear
"View [x] not found"
Cause: Missing or corrupted view file.
php artisan view:clear
If the file is genuinely missing, re-upload from the original package.
"Maximum execution time exceeded"
Cause: Long-running operation (backup, migration, AI analysis).
Increase PHP timeout:
max_execution_time = 300
Collecting Debug Info for Support
When reporting a bug, include:
php -v # PHP version
php artisan --version # Laravel version
mysql --version # MySQL version
cat .env | grep -E "^(APP_|DB_|MAIL_|QUEUE_)" # Config (without passwords!)
tail -50 storage/logs/laravel.log # Recent errors