Search code examples
phpvisual-studio-codexdebugvscode-remote

Xdebug not starting when use the XDEBUG_TRIGGER env on VS Code


I'm configuring Xdebug in VS Code and it doesn't work when I use the start_with_request=trigger setting. If I set the config value to yes it works. I think VS Code is not sending the env variables from the launch.json file.

My Xdebug ini file:

zend_extension=xdebug.so
xdebug.mode = debug
xdebug.start_with_request = trigger

My launch.json:

{
    // 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": 9003,
            "env": {
                "XDEBUG_TRIGGER": "true"
            }
        }
    ]
}

I use VSCode with Microsoft Remote-SSH extension on a Ubuntu VM and Windows 10. My Xdebug extension is the XDebug official extension.

Log from Xdebug:

[2393] Log opened at 2022-03-29 13:54:04.173262
[2393] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[2393] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[2393] [Config] INFO: Trigger value for 'XDEBUG_SESSION' not found, so not activating
[2393] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[2393] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[2393] [Config] INFO: Trigger value for 'XDEBUG_SESSION' not found, so not activating
[2393] Log closed at 2022-03-29 13:54:04.360936

Solution

  • vscode-php-debug dev here.

    This is a common misunderstanding. The provided launch.json only listens for Xdebug/DBGp connections - as the default name implies. If there was also a program setting in there, VS Code would also start a (php) process. And only in that case could VS Code contribute to the environment of that newly started process.

    So, assuming you are running a web server, you can only change Xdebug settings by modifying the php.ini or somehow change the process environment of that web server process...

    You can also check out other launch.json snippers by typing php at the end of the current snippet. Maybe some of them could be useful.

    Perhaps I should add a warning if somebody sets env without setting program...