在 Debian 下调试 Laravel,常见且实用的方式如下,从最常用到进阶逐步说明。
编辑 .env:
APP_DEBUG=true
APP_ENV=local
然后清缓存:
php artisan config:clear
php artisan cache:clear
✅ 页面会显示详细错误信息(适合开发环境)
dd() / dump()dd($user);
// 或
dump($request->all());
dd():打印并终止dump():打印继续执行Laravel 日志在:
storage/logs/laravel.log
实时查看:
tail -f storage/logs/laravel.log
安装:
composer require barryvdh/laravel-debugbar --dev
使用:
php artisan tinkerphp artisan tinker
示例:
User::first();
route('home');
非常适合调试模型、查询。
php artisan route:list
php artisan config:show
php artisan view:clear
sudo apt update
sudo apt install php-xdebug
查看版本:
php -m | grep xdebug
编辑:
/etc/php/8.2/cli/conf.d/20-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
# 或
sudo service apache2 restart
PHP Debugsudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
php artisan config:clear
php artisan route:clear
php artisan view:clear
✅ APP_DEBUG=true
✅ Laravel Debugbar
✅ tail -f laravel.log
✅ Xdebug(进阶)
如果你愿意,可以告诉我:
我可以给你更精确的 Debian 配置示例。