温馨提示×

debian中laravel怎样调试

小樊
42
2026-09-05 08:47:00
栏目: 智能运维

在 Debian 下调试 Laravel,常见且实用的方式如下,从最常用到进阶逐步说明。


一、基础调试(最常用)

1. 开启调试模式

编辑 .env:

APP_DEBUG=true
APP_ENV=local

然后清缓存:

php artisan config:clear
php artisan cache:clear

✅ 页面会显示详细错误信息(适合开发环境)


2. 使用 dd() / dump()

dd($user);
// 或
dump($request->all());
  • dd():打印并终止
  • dump():打印继续执行

3. 查看日志

Laravel 日志在:

storage/logs/laravel.log

实时查看:

tail -f storage/logs/laravel.log

二、Web 调试工具(强烈推荐)

1. Laravel Debugbar

安装:

composer require barryvdh/laravel-debugbar --dev

使用:

  • 页面底部会出现调试栏
  • 可查看 SQL、请求、视图、日志

三、命令行调试

1. php artisan tinker

php artisan tinker

示例:

User::first();
route('home');

非常适合调试模型、查询。


2. 查看路由 / 配置

php artisan route:list
php artisan config:show
php artisan view:clear

四、Xdebug(Debian + PHP 高级调试)

1. 安装 Xdebug

sudo apt update
sudo apt install php-xdebug

查看版本:

php -m | grep xdebug

2. 配置 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

3. 编辑器支持

  • VS Code:安装 PHP Debug
  • PHPStorm:直接支持 Xdebug
  • 可断点、单步调试

五、常见问题排查

1. 权限问题

sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache

2. 缓存导致“改了没效果”

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

六、推荐组合(开发环境)

✅ APP_DEBUG=true
✅ Laravel Debugbar
✅ tail -f laravel.log
✅ Xdebug(进阶)


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

  • 使用的是 Apache / Nginx / PHP built-in
  • PHP 版本
  • 是否用 Docker

我可以给你更精确的 Debian 配置示例。

0 踩