How to debug cli command in magento 2
For IDE PHPSTORM
Steps:
1) Export the key (if you are using docker, do it in container)
export XDEBUG_CONFIG='PHPSTORM'
export PHP_IDE_CONFIG="serverName=vasan.dev.local.com"
2) Start the phpstorm Bug Debug
3) Execute the cli command
XDEBUG_SESSION_START=PHPSTORM php bin/magento vasan:product:import
For IDE VSCODE
xdebug ini configuration for web debug
zend_extension=xdebug.so
xdebug.idekey=VSCODE
xdebug.mode=develop,debug
xdebug.discover_client_host=1
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.log=/tmp/xdebug.log
xdebug ini configuration for cli debug
zend_extension=xdebug.so
xdebug.idekey=VSCODE
xdebug.mode=develop,debug
xdebug.discover_client_host=0
xdebug.client_host=50.0.0.1
#xdebug.client_host=host.docker.internal # use this if the static ip is not used
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.log=/tmp/xdebug.log
vscode launch.json configuration
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug (Magento 2)",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html/codepool": "${workspaceFolder}"
},
"log": true
}
]
}
For VSCODE step 1 and 3
export XDEBUG_CONFIG="client_host=50.0.0.1 client_port=9003 idekey=VSCODE mode=debug"
XDEBUG_SESSION_START=VSCODE php bin/magento my:command
Posted by vasan to vasan's deck (2024-11-04 05:54)