温馨提示×

centos下laravel如何调试

小樊
39
2026-09-27 00:27:50
栏目: 智能运维

在 CentOS 下调试 Laravel,一般从「日志 + 错误显示 + 调试工具 + 运行环境」几个方面入手。下面按常用程度给你一套实用方案。


一、最基础:打开错误显示(开发环境)

1. 修改 .env

APP_ENV=local
APP_DEBUG=true

⚠️ 生产环境 不要 开 APP_DEBUG=true

让配置生效:

php artisan config:clear

2. 检查 PHP 错误显示

编辑 php.ini(位置可能不同):

php --ini

确保:

display_errors = On
error_reporting = E_ALL

重启 PHP:

# PHP-FPM
systemctl restart php-fpm

# Apache
systemctl restart httpd

二、查看 Laravel 日志(最重要)

日志位置

storage/logs/laravel.log

实时查看:

tail -f storage/logs/laravel.log

修改日志级别(可选)

config/logging.php

'level' => 'debug',

三、使用 dd() / dump() 快速调试

dd($user);
// 或
dump($request->all());

常见位置:

  • Controller
  • Middleware
  • Artisan Command

四、Artisan 命令调试

查看路由

php artisan route:list

查看配置

php artisan config:show

清除缓存(CentOS 常踩坑)

php artisan config:clear
php artisan route:clear
php artisan cache:clear
php artisan view:clear

五、使用 Xdebug(推荐进阶)

1. 安装 Xdebug

yum install php-xdebug
# 或
pecl install xdebug

2. 配置 php.ini

[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003

重启 PHP:

systemctl restart php-fpm

3. 配合编辑器

  • PHPStorm
  • VSCode(Xdebug + PHP Debug 插件)

六、权限问题(CentOS 特有)

storage / bootstrap 权限

chown -R nginx:nginx storage bootstrap
chmod -R 775 storage

否则会出现:

  • 日志写不进去
  • 页面 500 但无报错

七、常见问题速查

现象 原因
空白页 APP_DEBUG=false
500 无日志 storage 无写权限
路由无效 路由缓存未清
改了配置没用 config:cache

八、推荐调试组合(实用)

✅ 新手
APP_DEBUG=true + tail laravel.log

✅ 进阶
Xdebug + PHPStorm

✅ 线上
日志 + Sentry


如果你愿意,可以告诉我:

  • CentOS 版本(7 / 8 / Stream)
  • PHP 版本
  • Web 服务(Nginx / Apache)
  • 具体报错信息

我可以给你更精确的调试方案。

0 踩