温馨提示×

怎么调试debian laravel项目

小樊
39
2026-09-20 13:59:18
栏目: 智能运维

在 Debian 上调试 Laravel 项目,通常可以从环境检查、日志、错误显示、调试工具、Xdebug几个方面入手。下面给你一套比较实用的流程。


一、基础环境确认(先排除低级问题)

1. 查看 PHP 版本

php -v

Laravel 对 PHP 版本有要求(如 Laravel 10 需要 PHP 8.1+)

2. 确认必要扩展

php -m | grep -E "mbstring|xml|curl|json|sqlite|pdo|openssl"

缺失可安装:

sudo apt install php-mbstring php-xml php-curl

3. 确认 Composer

composer -V

二、打开 Laravel 错误显示(开发环境)

1. 修改 .env

APP_ENV=local
APP_DEBUG=true

2. 清除配置缓存

php artisan config:clear
php artisan cache:clear

三、查看错误日志(最重要)

Laravel 日志

tail -f storage/logs/laravel.log

PHP / Nginx / Apache 日志

# PHP
tail -f /var/log/php*-fpm.log

# Nginx
tail -f /var/log/nginx/error.log

# Apache
tail -f /var/log/apache2/error.log

四、使用 Laravel 自带调试工具

1. dd() / dump()

dd($variable);
// 或
dump($variable);

2. php artisan 排错

php artisan route:list
php artisan migrate:status
php artisan config:show

五、使用 Tinker 调试

php artisan tinker

可直接测试模型、查询:

App\Models\User::first();

六、配置 Xdebug(强烈推荐)

1. 安装 Xdebug

sudo apt install php-xdebug

2. 编辑 php.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 php*-fpm

3. 配合 VS Code / PHPStorm

  • 安装 PHP Debug 插件
  • 配置 launch.json
  • 打断点调试

七、常见 Debian + Laravel 问题

1. 权限问题

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

2. 路由 404

  • Nginx 需配置:
try_files $uri $uri/ /index.php?$query_string;

3. 定时任务不执行

php artisan schedule:list
crontab -e
* * * * * cd /path && php artisan schedule:run

八、快速自检清单

✅ APP_DEBUG=true
✅ 日志能看
✅ 权限正确
✅ PHP 扩展齐全
✅ Xdebug 可用


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

  • 用的是 Nginx 还是 Apache
  • Laravel 版本
  • 具体报错信息

我可以直接帮你精准定位问题。

0 踩