在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的配置,并確保它們正確設置。