温馨提示×

centos laravel报错怎么查

小樊
40
2026-09-24 03:00:11
栏目: 智能运维

在 CentOS 上运行 Laravel 报错时,可以按照下面一套比较系统的流程来排查。


一、先看 Laravel 自身报错

1️⃣ 开启调试模式

编辑 .env:

APP_DEBUG=true

然后清缓存:

php artisan config:clear
php artisan cache:clear

⚠️ 生产环境慎用,排查完要改回 false


2️⃣ 查看 Laravel 日志

tail -f storage/logs/laravel.log

常见错误:

  • SQL 错误
  • 路由找不到
  • 类不存在
  • 权限问题

二、CentOS 系统层面排查

3️⃣ PHP 版本 & 扩展

php -v
php -m

Laravel 需要的常见扩展:

  • mbstring
  • xml
  • ctype
  • json
  • tokenizer
  • bcmath
  • openssl
  • pdo
  • gd(图片相关)

缺少就装:

yum install php-mbstring php-xml php-bcmath

4️⃣ 文件权限问题(CentOS 最常见)

chown -R nginx:nginx /var/www/your_project
chmod -R 755 /var/www/your_project
chmod -R 777 storage bootstrap/cache

如果使用 SELinux:

setenforce 0   # 临时关闭

或:

chcon -R -t httpd_sys_rw_content_t storage

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

5️⃣ Nginx 报错

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

常见:

  • Permission denied
  • File not found
  • rewrite or internal redirection cycle

确保:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

6️⃣ Apache 报错

tail -f /var/log/httpd/error_log

四、Composer / 依赖问题

7️⃣ 重装依赖

composer install
composer dump-autoload

8️⃣ 常见 Composer 错误

  • PHP 版本不匹配
  • ext-xxx 缺失
  • 内存不足:
php -d memory_limit=-1 composer install

五、数据库问题

9️⃣ 数据库连不上

检查:

php artisan tinker
>>> DB::connection()->getPdo();

CentOS 常见问题:

  • MySQL 没启动
systemctl status mysqld
  • 防火墙
firewall-cmd --list-all

六、快速定位错误的方法(推荐)

✅ 直接命令行复现:

php artisan serve

或:

php artisan route:list
php artisan migrate

七、如果你愿意,我可以直接帮你定位

你可以把 具体报错信息 发给我,比如:

  • laravel.log 内容
  • 浏览器报错页面
  • nginx error.log
  • 命令行报错

我可以直接告诉你 是哪一步出的问题、怎么改。

0 踩