在 CentOS 上调试 Laravel,通常可以从 日志、调试工具、PHP 配置、开发环境 几个方面入手。下面给你一套常用且实用的方案。
.envAPP_ENV=local
APP_DEBUG=true
⚠️ 生产环境 不要 开 APP_DEBUG=true
编辑 php.ini(位置通常是 /etc/php.ini 或 /etc/php.d/)
display_errors = On
error_reporting = E_ALL
重启 PHP:
systemctl restart php-fpm
# 或
systemctl restart httpd
tail -f storage/logs/laravel.log
\Log::info('测试数据', ['data' => $data]);
\Log::error('出错了', ['msg' => $e->getMessage()]);
dump($user);
dd($request->all());
composer require barryvdh/laravel-debugbar --dev
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
浏览器访问页面即可看到:
php artisan route:list
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan tinker
User::first();
yum install php-xdebug
xdebug.inizend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
适合:
chmod -R 755 storage bootstrap/cache
chown -R nginx:nginx storage
setenforce 0
(生产不建议长期关闭)
✅ APP_DEBUG=true
✅ tail -f storage/logs/laravel.log
✅ dd() / dump()
✅ Laravel Debugbar
如果你愿意,可以告诉我:
我可以直接给你针对性的调试配置。