温馨提示×

laravel在centos报错怎么查

小樊
45
2026-10-02 21:34:15
栏目: 智能运维

在 CentOS 上运行 Laravel 项目报错时,可以按下面系统化的排查流程来查问题和定位日志。


一、先看 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


三、Web 服务器错误(Nginx / Apache)

1️⃣ Nginx 错误日志

tail -100 /var/log/nginx/error.log

常见错误:

  • Permission denied
  • File not found
  • connect() failed (111: Connection refused)

2️⃣ Apache 错误日志

tail -100 /var/log/httpd/error_log

四、PHP 错误日志

查看 php.ini 中错误日志位置:

php --ini

常见路径:

/var/log/php-fpm/error.log

或:

tail -100 /var/log/php-fpm/www-error.log

五、权限问题(CentOS 最常见)

Laravel 需要写权限的目录:

chown -R nginx:nginx storage bootstrap/cache
chmod -R 755 storage bootstrap/cache

如果是用 php artisan serve:

chown -R $USER:$USER storage

六、SELinux 问题(CentOS 特有)

CentOS 默认开启 SELinux,常导致:

  • 上传失败
  • storage 写不进去
  • 502 / 403

查看是否开启:

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

七、PHP 版本 / 扩展问题

检查 Laravel 所需扩展:

php -m

常见缺的:

  • mbstring
  • xml
  • curl
  • gd
  • zip
  • bcmath
  • openssl

安装示例(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

如果你愿意,可以把具体报错信息(命令行或日志内容)贴出来,我可以直接帮你判断是哪一种问题。

0 踩