Setting up VSCode with xdebug: pathMapping
Thus is as much a reference to myself as well as others who might find this helpful. I am running VSCODE with xdebug and drupalvm and the following works for me after setting the following in php.ini
php_xdebug_idekey: VSCODE
{
// 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,
"pathMappings": {
"/var/www/drupalvm/drupal": "${workspaceRoot}/drupal",
},
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
I guess you're using the PHP debug extension ?
https://github.com/felixfbecker/vscode-php-debug
The README.md says the following:
Remote Host Debugging
To debug a running application on a remote host, you need to tell XDebug to connect to a different IP than localhost. This can either be done by setting xdebug.remote_host to your IP or by setting xdebug.remote_connect_back = 1 to make XDebug always connect back to the machine who did the web request. The latter is the only setting that supports multiple users debugging the same server and "just works" for web projects. Again, please see the XDebug documentation on the subject for more information.
To make VS Code map the files on the server to the right files on your local machine, you have to set the pathMappings settings in your launch.json. Example:
// server -> local
"pathMappings": {
"/var/www/html": "${workspaceRoot}/www",
"/app": "${workspaceRoot}/app"
}
Please also note that setting any of the CLI debugging options will not work with remote host debugging, because the script is always launched locally. If you want to debug a CLI script on a remote host, you need to launch it manually from the command line.