How to PHP debug multiple websites in VS Code

Viewed 633

Expected behavior:

I have multiple PHP projects on different servers, usually I debug them with PhpStorm which allows me to configure path mappings for remote debugging per server. Thus I can have the same remote paths e.g. /var/www/html for different servers.

Problem description:

So far I have been unable to configure multiple servers with the same remote paths using VSCode.

I use the most used php-debug plugin for VSCode and have not found any information regarding this issue on the projects GitHub page or anywhere else.

Currently I do not think configuring multiple remote servers using VSCode is possible at this time but in case someone knows a way I would appreciate it.

Current configuration:

With the following configuration I can only debug one project at once and have to change the paths manually when I want to debug another project on another server with the same remote paths.

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "pathMappings": {
            "/var/www/html": "/local/project/path",
            "/var/www/html/src/shared:": "/local/shared/src/path",
        }
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000
    }
]

}

1 Answers

Step 1

To debug multiple websites with VSCode first add multiple configurations to the vscode-php-debug extensions config (Run->Open Configurations) with different names.

{
"version": "0.2.0",
"configurations": [
    {
        "name": "website 1",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "pathMappings": {
            "/var/www/html": "/local/project/path1",
        }
    },
           {
        "name": "website 2",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "pathMappings": {
            "/var/www/html": "/local/project/path2",
        }
    },
    {
        "name": "website 3",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "pathMappings": {
            "/var/www/html": "/local/project/path3",
        }
    },
]
}

Step 2

You then have to select the appropriate configuration before debugging your code by clicking on the current configuration in the bottom left hand corner or writing debug in the top bar (ctrl+t and remove the hash) (which will make that configuration the default for the current session and immediately launch debugging).

Related