在 CentOS 下调试 Laravel,一般从「日志 + 错误显示 + 调试工具 + 运行环境」几个方面入手。下面按常用程度给你一套实用方案。
.envAPP_ENV=local
APP_DEBUG=true
⚠️ 生产环境 不要 开
APP_DEBUG=true
让配置生效:
php artisan config:clear
编辑 php.ini(位置可能不同):
php --ini
确保:
display_errors = On
error_reporting = E_ALL
重启 PHP:
# PHP-FPM
systemctl restart php-fpm
# Apache
systemctl restart httpd
storage/logs/laravel.log
实时查看:
tail -f storage/logs/laravel.log
config/logging.php
'level' => 'debug',
dd() / dump() 快速调试dd($user);
// 或
dump($request->all());
常见位置:
php artisan route:list
php artisan config:show
php artisan config:clear
php artisan route:clear
php artisan cache:clear
php artisan view:clear
yum install php-xdebug
# 或
pecl install xdebug
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
chown -R nginx:nginx storage bootstrap
chmod -R 775 storage
否则会出现:
| 现象 | 原因 |
|---|---|
| 空白页 | APP_DEBUG=false |
| 500 无日志 | storage 无写权限 |
| 路由无效 | 路由缓存未清 |
| 改了配置没用 | config:cache |
✅ 新手
APP_DEBUG=true + tail laravel.log
✅ 进阶
Xdebug + PHPStorm
✅ 线上
日志 + Sentry
如果你愿意,可以告诉我:
我可以给你更精确的调试方案。