在Debian上调试Laravel应用程序可以通过多种方式进行,以下是一些常用的调试技巧:
sudo apt-get update
sudo apt-get install php-xdebug
/etc/php/7.4/cli/php.ini
或 /etc/php/7.4/fpm/php.ini
),添加以下配置:zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=yes
sudo systemctl restart apache2
对于Nginx和PHP-FPM,请运行:
sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm
请确保将 php7.4-fpm
替换为你的PHP版本。
composer require barryvdh/laravel-debugbar --dev
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
.env
文件中,将 APP_DEBUG
设置为 true
,以启用Laravel的调试模式。APP_DEBUG=true
@if(env('APP_DEBUG'))
{{-- Debugbar will be shown in this block --}}
@endif
这将在开发环境中显示Debugbar面板。
composer require laravel/telescope
php artisan telescope:install
php artisan telescope:dev
Telescope提供了一个对请求、异常、日志、数据库查询等的深入了解,是一个优雅的调试助手。
composer global require laravel/tinker
php artisan tinker
在Tinker中,可以使用 DB::listen()
函数监听数据库查询,或使用 dump()
和 dd()
函数输出变量和调试信息。
storage/logs/laravel.log
。你可以通过修改 .env
文件中的 APP_DEBUG
环境变量来控制是否显示错误信息。确保安装了所有必要的软件包,如Nginx、PHP、PHP-FPM、MySQL、Composer和Laravel本身。配置Nginx以正确代理请求到Laravel的前端控制器 index.php
。
以上步骤应该能帮助你在Debian环境下有效地调试Laravel应用程序。如果遇到问题,请检查Xdebug和IDE的配置,并确保它们正确设置。