Vscode-php-debug: Xdebug 3 compatibility

Created on 15 Jun 2020  路  25Comments  路  Source: xdebug/vscode-php-debug

Xdebug 3 is on its way. I'm not sure if there are any changes required here, but now seems like as good a time as any to bring attention to the subject. There are quite a few changes on the user configuration side according to the upgrade guide.

released

Most helpful comment

Successfully got VSCode to debug my cli apps on Windows with PHP 7.4 and XDebug 3.0.1, here are my configs

launch.json

{
    "runtimeExecutable": "C:/Users/XXX/Dev/bin/php7/php.exe",
    "name": "Launch currently open script",
    "type": "php",
    "request": "launch",
    "program": "${file}",
    "cwd": "${fileDirname}",
    "port": 9000,
}

php.ini

[XDebug]
;  place php_xdebug-3.0.1-7.4-vc15-x86_64.dll in ext folder
zend_extension=xdebug-3.0.1-7.4-vc15-x86_64

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9000

All 25 comments

@TRowbotham I do not think this project is maintained any longer, there are pull requests that have been open for more than a year and the author himself said that he does not have enough time anymore to maintain this project.

@elovin This is really sad, unfortunately I don't find any debugging solution for vscode

I confirm some changes may be required.
Xdebug v2.9.8 was working fine, but not Xdebug v3.0.0, same php version : PHP 7.4.12 (cli) (built: Nov 18 2020 09:34:43) ( NTS )

I see, I been wracking my head on this for many hours.

Xdebug's default port changed to 9003 (it was 9000), make sure that you update your VSCode lanuch.json file to use port 9003 if you aren't using a custom port.

@diego-vieira not sure how? The default port was changed from 9000 to 9003. Are you saying you can
set breakpoints which get hit with that config?

What are your xdebug php ini settings?

"xdebugSettings": {
"max_children": 10000,
"max_data": 10000,
"show_hidden": 1
}

It's not working on php8

Did someone get it to run?

Even with the 9003 Port and
xdebug.mode= debug
xdebug.start_with_request = yes

it won't work for us.

Any further tipps or information?

I'm also looking for a solution. In this Lando issue https://github.com/lando/lando/issues/2718, this is the recommended configuration, the author reports that it works for PHPStorm:

xdebug.mode = debug
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.start_with_request = trigger

But, it didn't work for me on VSCode.

I'm also looking for a solution. In this Lando issue lando/lando#2718, this is the recommended configuration, the author reports that it works for PHPStorm:

xdebug.mode = debug
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.start_with_request = trigger

But, it didn't work for me on VSCode.

Didn't work for me on VSCode as well.

Did you change also the Port from 9000 to 9003?

In my case, I use to change from the default port to a custom port:

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9099

xdebug.mode = debug
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.start_with_request = trigger
{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9099,

            "pathMappings": {
                "/app/www": "${workspaceRoot}/www"
            },

            "xdebugSettings": {
                "max_children": 10000,
                "max_data": 10000,
                "show_hidden": 1
            }
        }
    ]
}

As far as I can tell, this is the sum of recommendations that should work on VSCode.

PD: This configuration doesn't work. See below for the configuration that works OK.

@anibalsanchez and this is actually working for you? That config is a mixture of xdebug 2 and 3. I would be surprised if step debugging/breakpoints was actually working.

I got Xdebug 3 working with this VS Code extension. I develop a local environment tool for WordPress (which uses Docker) and looked at adding it here: https://github.com/WordPress/gutenberg/pull/27346.

The main thing for me is that discover_client_host doesn't seem to work with Docker and macOS, so I set the host to host.docker.internal in that situation.

My Xdebug settings are:

xdebug.start_with_request=yes
xdebug.mode=debug
xdebug.client_host="host.docker.internal" // for macOS and windows
xdebug.discover_client_host=true // for Linux

My launch.json is:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html/wp-content/plugins/gutenberg": "${workspaceRoot}/"
            }
        }
    ]
}

The path mapping is just the path to my WordPress plugin inside of Docker, pointed at the VSCode root directory.

Step debugging is working for me with this setup in VS Code with Xdebug 3 installed in the Docker service.

@anibalsanchez and this is actually working for you? That config is a mixture of xdebug 2 and 3. I would be surprised if step debugging/breakpoints was actually working.

No, it didn't work. You are right.

Following https://github.com/felixfbecker/vscode-php-debug/issues/411#issuecomment-737564004, this version (only with settings for Xdebug 3) works fine:

;;;;;;;;;;;;;;;;;;;
; xdebug-3.0.0
; https://xdebug.org/docs/upgrade_guide
;;;;;;;;;;;;;;;;;;;
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = true
; xdebug.client_host = ${LANDO_HOST_IP}
xdebug.client_port = 9099
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9099,

            "pathMappings": {
                "/app/www": "${workspaceRoot}/www"
            }
        },

Thanks @anibalsanchez and @noahtallen. Finally got step debug working!

VS Code

{
    // 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,
            "pathMappings": {
                "/Users/jason/Sites/services": "${workspaceRoot}",
            }
        }
    ]
}

PHP INI

[xdebug]
zend_extension="/usr/local/Cellar/php/7.4.8/pecl/20190902/xdebug.so"
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = true

I'm using brew on MacOS so ignore my zend_extension path.

After updating my configs I restarted php

brew services restart [email protected]

Also a good debugging tip is to use die(xdebug_info()); to check if xdebug is running, it's version and what debug mode it's running. I noticed I was in profile mode even though my ini said debug, so that may have been part of my problem.

Successfully got VSCode to debug my cli apps on Windows with PHP 7.4 and XDebug 3.0.1, here are my configs

launch.json

{
    "runtimeExecutable": "C:/Users/XXX/Dev/bin/php7/php.exe",
    "name": "Launch currently open script",
    "type": "php",
    "request": "launch",
    "program": "${file}",
    "cwd": "${fileDirname}",
    "port": 9000,
}

php.ini

[XDebug]
;  place php_xdebug-3.0.1-7.4-vc15-x86_64.dll in ext folder
zend_extension=xdebug-3.0.1-7.4-vc15-x86_64

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9000

Does anyone know how to use trigger mode?

xdebug.start_with_request=trigger

I can't trigger it from the command line or the browser.

When set to yes it works.

In order to avoid xdebug from complaining on each request when xdebug client is stopped, this should be set to trigger or even omitted since xdebug.mode = debug sets this to trigger.

Change the listened port works for me. Here is the upgrade doc.

The default value has also changed from 9000 to 9003.

BTW, it's better if the project readme could be improved.

@felixfbecker is it possible to pass in "xdebug.mode = debug" via the launch.json? If I enable it globally via php.ini then it always reports a warning if run unit tests without listening to xdebug for example.

Depends on whether you run a CLI script or the "Listen" mode I think. In CLI ("Launch") mode you could pass runtimeArgs with -d to set ini settings.

@felixfbecker I tried to use -d with runtimeArgs but I have no clue why it does not work. And I also tried to set it via an ENV

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html/": "${workspaceRoot}"
            },
            "hostname": "localhost",
            "runtimeArgs": [
                "-d XDEBUG_MODE=debug"
            ],
            "env": {
                "XDEBUG_MODE": "debug"
            }
        }
    ]
}

Can you help me?

That is the "Listen" mode I talked about, not the "CLI/launch" mode. Settings like runtimeArgs and env will have no effect because VS Code is not what launches the php process. I don't see a way how it could work in that scenario.
It's also a bit off-topic for this issue. If you want to keep discussing it, please open a new issue (but as said I don't know how it could work, sorry).

:tada: This issue has been resolved in version 1.14.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

debian server, windows 10 client, vscode:

php.ini:

[XDebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = 192.168.3.32
xdebug.client_port = 9000
xdebug.log = /var/log/php.xdebug.log

.vscode\launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/var/www": "${workspaceRoot}/src"
            },
            "xdebugSettings": {
                "max_children": 10000,
                "max_data": 10000,
                "show_hidden": 1
            }
        }
    ]
}
Was this page helpful?
0 / 5 - 0 ratings