在 Debian 上调试 Laravel,通常可以从 日志、调试模式、断点调试、性能分析、队列/任务 等几个方面入手。下面按“常用 → 进阶”给你一套完整方案。
# .env
APP_DEBUG=true
APP_ENV=local
⚠️ 生产环境一定关闭
tail -f storage/logs/laravel.log
常见错误:
dd() / dump()dd($user);
dump($request->all());
dd():打印并终止dump():打印继续运行\DB::enableQueryLog();
// 执行查询
dd(\DB::getQueryLog());
或使用 barryvdh/laravel-debugbar(强烈推荐)。
tail -f /var/log/php8.2-fpm.log
# 或
journalctl -xe
常见路径:
/var/log/php8.2-fpm.log
/var/log/nginx/error.log
/var/log/apache2/error.log
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
php -i | grep "display_errors"
php -i | grep "error_reporting"
建议:
display_errors = On
error_reporting = E_ALL
sudo apt install php8.2-xdebug
确认:
php -v
# /etc/php/8.2/mods-available/xdebug.ini
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
重启 PHP:
sudo systemctl restart php8.2-fpm
安装插件:PHP Debug
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003
}
]
}
然后:
php artisan route:list
request()->all()
request()->headers->all()
php artisan queue:failed
php artisan queue:retry all
tail -f storage/logs/worker.log
composer require barryvdh/laravel-debugbar --dev
浏览器底部会显示:
composer require laravel/telescope
php artisan telescope:install
php artisan migrate
可查看:
| 问题 | 解决 |
|---|---|
| 500 错误 | 看 laravel.log |
| 权限拒绝 | chown www-data |
| 路由 404 | php artisan route:clear |
| 缓存异常 | php artisan cache:clear |
| Composer 权限 | 使用非 root 用户 |
✅ 本地开发
APP_DEBUG=truelaravel-debugbar✅ Debian 服务器
tail -f laravel.logphp-fpm 日志queue:work --verbose如果你愿意,可以告诉我:
我可以直接帮你定位具体错误。