you need to install php-xdebug on your system, the following document explains how to install it:
start your vscode, make sure you have installed the xdebug extension for vscode then create a file in .vscode/launch.json, copy & paste this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "PHP CLI some_file.php",
"type": "php",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/some_file.php",
"args": [
"hello",
"world"
],
"env": {
"XDEBUG_MODE": "debug",
"XDEBUG_TRIGGER": "1",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "PHP CLI EXTERNAL CONSOLE some_file.php",
"type": "php",
"request": "launch",
"externalConsole": true,
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/some_file.php",
"args": [
"hello",
"world"
],
"env": {
"XDEBUG_MODE": "debug",
"XDEBUG_TRIGGER": "1",
"XDEBUG_CONFIG": "client_port=${port}"
}
}
]
}
now for example, create a some_file.php, paste this:
<?php
var_dump($argv);
?>
you can now debug the cli by pressing the play button like you mentioned above, select "PHP CLI some_file.php" or "PHP CLI EXTERNAL CONSOLE some_file.php" in the drop down, and press the green play button or press F5, mark the breakpoint at line 2 or edit some_file.php and mark it wherever you want, that's it.
pay attention to the differences between the two, the external one has the following parameters: externalConsole": true,
and if you want to trigger the debug from your terminal to vscode, select "Listen for Xdebug" from the drop down and press the green play button or press F5, now from your terminal, type this:
XDEBUG_MODE=debug;XDEBUG_TRIGGER=1 php some_file.php hello world