yiisoft/yii2-debug
Yii2 Debug adds a bottom-page debug toolbar and detailed standalone panels for Yii 2 apps, helping you inspect requests, logs, profiling, DB queries, and more during development. Install via Composer and enable the debug module in config.
Installation:
composer require --dev yiisoft/yii2-debug
Add to your config/web.php (or relevant environment config):
'modules' => [
'debug' => [
'class' => 'yiisoft\yii2\debug\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.*'], // Restrict access
],
],
First Use Case:
/debug in your browser to see the dashboard.Key Initial Files:
vendor/yiisoft/yii2-debug/src/Module.php (core module logic).vendor/yiisoft/yii2-debug/src/panels/ (individual panel implementations).Debugging Requests/Responses:
config/web.php:
'debug' => [
'modules' => [
'debug' => [
'panels' => [
'yiisoft\yii2\debug\panels\RequestsPanel',
],
],
],
],
Database Queries:
yiisoft\yii2\debug\panels\DbPanel to log and analyze SQL queries.config/web.php:
'components' => [
'db' => [
'enableProfiling' => true, // Critical for query logging
'enableLogging' => true,
],
],
Performance Profiling:
Yii::$app->getProfiler()->enable();
Custom Panels:
yiisoft\yii2\debug\Panel to create domain-specific panels (e.g., for caching or third-party APIs).namespace app\debug\panels;
use yiisoft\yii2\debug\Panel;
class MyCustomPanel extends Panel {
public $name = 'My Custom Panel';
public function getData() { /* ... */ }
}
config/web.php:
'panels' => [
'app\debug\panels\MyCustomPanel',
],
Error Tracking:
config/web.php:
'components' => [
'errorHandler' => [
'exceptionHandler' => 'app\components\DebugExceptionHandler', // Custom handler
],
],
Performance Overhead:
'debug' => [
'class' => 'yiisoft\yii2\debug\Module',
'enabled' => Yii::$app->getRequest()->getHostInfo() === 'localhost', // Example condition
],
Yii::$app->getProfiler()->disable() in production.Sensitive Data Exposure:
/debug publicly. Restrict allowedIPs strictly:
'allowedIPs' => ['192.168.1.100'], // Only your IP!
yiisoft\yii2\debug\DataMasker to sanitize data:
Yii::$app->debug->dataMasker->mask('password', '****');
Panel Conflicts:
yiisoft\yii2\debug\panels\AssetsPanel) may not work with custom asset managers.Database Panel Quirks:
DbPanel may not log queries from raw PDO statements or non-Yii DB components.DbCommand or wrap raw queries in Yii::$app->db->createCommand().Caching Issues:
yiisoft\yii2\debug\panels\CachePanel, ensure cache components are properly configured:
'components' => [
'cache' => [
'class' => 'yiisoft\yii2\caching\FileCache',
],
],
Log Filtering:
yiisoft\yii2\debug\DataMasker to filter sensitive data in logs:
Yii::$app->debug->dataMasker->rules = [
'password' => ['mask' => '****'],
'token' => ['mask' => '***'],
];
Custom Logs:
yiisoft\yii2\debug\Panel and implementing getData():
public function getData() {
return [
'custom_logs' => Yii::getLogger()->getLogs(),
];
}
Remote Debugging:
/debug:
ssh -L 8080:localhost:80 user@your-server.com
http://localhost:8080/debug locally.Panel Order:
config/web.php:
'panels' => [
'yiisoft\yii2\debug\panels\RequestsPanel',
'yiisoft\yii2\debug\panels\DbPanel',
],
Debugging Debug:
Yii::$app->getRequest()->getHostInfo() matches allowedIPs.Response::send()).How can I help you explore Laravel packages today?