在 Debian 上调试 Laravel,常见且实用的方法有下面几类,按「从快到专业」给你梳理一下。
.envAPP_DEBUG=true
APP_ENV=local
然后清缓存:
php artisan config:clear
php artisan cache:clear
这样页面出错会显示详细错误。
Laravel 日志在:
storage/logs/laravel.log
实时查看:
tail -f storage/logs/laravel.log
也可以自己写日志调试:
\Log::info('测试数据', ['data' => $data]);
dd($var); // 打印并终止
dump($var); // 打印不终止
php artisan route:list
php artisan tinker
User::first();
php artisan config:show
sudo apt update
sudo apt install php-xdebug
编辑:
/etc/php/8.2/cli/php.ini
# 或 fpm 配置(web 调试)
/etc/php/8.2/fpm/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
重启:
sudo systemctl restart php8.2-fpm
launch.json✅ 适合复杂逻辑、循环、API 调试
composer require barryvdh/laravel-debugbar --dev
浏览器右下角会出现调试面板(SQL、请求、视图等)
php -v
sudo chown -R www-data:www-data storage bootstrap/cache
chmod -R 775 storage
sudo systemctl status nginx
sudo systemctl status php8.2-fpm
✅ 日常:
APP_DEBUG=true + tail -f laravel.log + dd()
✅ 进阶:
Laravel Debugbar
✅ 专业:
Xdebug + VS Code
如果你告诉我:
我可以给你一份完全贴合你服务器的调试配置。