Default entries for PHP debug (no launch.json file was present before that).
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Created them using this way:
You can run through questions where both visual-studio-code & xdebug tags are present to see other possible configs (but usually that would be just default entries).
P.S. I had to add the following bit for Xdebug to actually try to debug (for "Launch currently open script" entry .. which runs the script in CLI environment). Without it it was just executing it (PhpStorm IDE is better in this regard as it automatically adds such bit when "Debug" button is used).
The IDE key can be anything, it just that this environment variable to be present (at very least here in my setup on Windows 10).
"env": {
"XDEBUG_CONFIG": "idekey=VSCODE"
},
this also works for me:
"env": {
"XDEBUG_CONFIG": ""
},
I've also tried "XDEBUG_SESSION": "1"
.. but it did not worked for me.
Without that (or when you cannot override it as you already have such environment variable with your own stuff) you may need to have xdebug.start_with_request = yes
in your php.ini (which tells Xdebug to try to debug every single script -- it's inconvenient to have it there as it will be applied to ALL PHP scripts that are run with that php.ini) .. or have xdebug_break();
in your PHP code.
Yet another way is to configure "program": "${file}"
line and specify PHP interpreter there as well as any Xdebug config (which also is not super convenient but is more flexible is certain scenarious, e.g. when you have multiple PHP on your system and have to run this script with non-default one), for example:
"program": "/path/to/php -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 -dxdebug.start_with_request=yes ${file}"