在 CentOS 上调试 Laravel 错误,通常可以从日志、配置、运行环境、调试工具几个方面入手。下面按实用顺序说明。
.envAPP_DEBUG=true
APP_ENV=local
然后清缓存:
php artisan config:clear
php artisan cache:clear
生产环境不建议长期开启
APP_DEBUG=true
Laravel 默认日志位置:
storage/logs/laravel.log
实时查看:
tail -f storage/logs/laravel.log
常见错误类型:
php --ini
log_errors = On
error_log = /var/log/php/php_errors.log
查看:
tail -f /var/log/php/php_errors.log
如果没有:
sudo mkdir -p /var/log/php
sudo chown apache:apache /var/log/php
Laravel 需要写权限:
sudo chown -R nginx:nginx /var/www/your_project
# 或 apache:apache
sudo chmod -R 755 storage bootstrap/cache
sudo chmod -R 777 storage bootstrap/cache # 临时调试
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log
常见:
Nginx 示例:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
dd($request->all());
composer require laravel/telescope
php artisan telescope:install
php artisan migrate
访问:
/project/telescope
可看:
php artisan serve
或手动执行:
php artisan your:command
查看具体报错。
| 现象 | 原因 |
|---|---|
| 500 错误 | APP_DEBUG=false |
| storage 不可写 | 权限问题 |
| Class not found | composer 未 autoload |
| SQL 报错 | 看 laravel.log |
| 空白页 | PHP 报错被关 |
如果你愿意,可以:
我可以帮你精准定位。