在 CentOS 上运行 Laravel 项目报错时,可以按下面系统化的排查流程来查问题和定位日志。
Laravel 的错误日志通常在:
storage/logs/laravel.log
查看最新错误:
tail -100 storage/logs/laravel.log
如果是 500 错误但页面没显示,大概率是这里有异常。
编辑 .env:
APP_DEBUG=true
APP_ENV=local
然后清缓存:
php artisan config:clear
php artisan cache:clear
⚠️ 生产环境不建议长期开启 APP_DEBUG=true
tail -100 /var/log/nginx/error.log
常见错误:
Permission deniedFile not foundconnect() failed (111: Connection refused)tail -100 /var/log/httpd/error_log
查看 php.ini 中错误日志位置:
php --ini
常见路径:
/var/log/php-fpm/error.log
或:
tail -100 /var/log/php-fpm/www-error.log
Laravel 需要写权限的目录:
chown -R nginx:nginx storage bootstrap/cache
chmod -R 755 storage bootstrap/cache
如果是用 php artisan serve:
chown -R $USER:$USER storage
CentOS 默认开启 SELinux,常导致:
查看是否开启:
getenforce
临时关闭测试:
setenforce 0
✅ 正确做法(推荐):
setsebool -P httpd_unified 1
semanage fcontext -a -t httpd_sys_rw_content_t '/path/to/laravel/storage(/.*)?'
restorecon -Rv /path/to/laravel/storage
检查 Laravel 所需扩展:
php -m
常见缺的:
安装示例(PHP 8.1):
yum install php81-php-mbstring php81-php-xml php81-php-curl
php artisan
或:
php artisan route:list
如果这里报错,说明是 代码 / 配置问题,不是 Web 服务器问题。
| 现象 | 查哪里 |
|---|---|
| 白屏 / 500 | storage/logs/laravel.log |
| 404 | Nginx / Apache 配置 |
| 502 | php-fpm 是否运行 |
| 上传失败 | SELinux / 权限 |
| 命令报错 | php artisan |
如果你愿意,可以把具体报错信息(命令行或日志内容)贴出来,我可以直接帮你判断是哪一种问题。