Search code examples
windowsvisual-studio-codexdebuglaradock

Xdebug is not working with Visual studio code when using Laradock on Windows 10


I try to configure Xdebug with Laradock with visual code on windows 10 machine.

I see that the Xdebug is enabled when using phpinfo(); I get these values:

Xdebug Version      2.9.8
xdebug.remote_host  host.docker.internal
xdebug.remote_port  9000

I have also enabled this configuration in Visual Code in the debug:

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "log": true,
            "stopOnEntry":true,
            "pathMappings": {
                "/var/www": "${workspaceRoot}/public",
            },
            "ignore": [
                "**/vendor/**/*.php"
            ]
        }
    ]

I have tested starting telnet using this command: telnet 192.168.1.10 9000 to see that I can connect to the debug session.

What do I miss to get the php-fpm connect back to my visual code session when I launch a browser? Do I need to send the key or should it just be to start the browser?

Any suggestion on more debugging I an do to find where the request get stuck? Any log for xdebug?


Solution

  • After updating the laradock\php-fpm\xdebug.ini and laradock\workspace\xdebug.ini like this I got it work:

    xdebug.remote_host=host.docker.internal
    xdebug.remote_connect_back=0
    xdebug.remote_port=9000
    xdebug.idekey=VSCODE
    
    xdebug.remote_autostart=0
    xdebug.remote_enable=0
    xdebug.cli_color=0
    xdebug.profiler_enable=0
    xdebug.profiler_output_dir="~/xdebug/phpstorm/tmp/profiling"
    
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.var_display_max_children=-1
    xdebug.var_display_max_data=-1
    xdebug.var_display_max_depth=-1
    

    I also modified the .vscode\launch.json like this:

    {
        // 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",
                //"type": "pwa-chrome",
                //"url": "http://127.0.0.1//posts/first",
                "port": 9000,
                "log": true,
                "stopOnEntry":false,
                "pathMappings": {
                    "/var/www": "I:\\dev\\project-z",
                },
                "ignore": [
                    "**/vendor/**/*.php"
                ]
            }
        ]
    }
    

    Since I had it on "stopOnEntry":true" I found out the pathMappings was not correct set. It was complaining about the index.php was not found (This fault came after, the first fault). I think the original fault was the "xdebug.remote_connect_back=0" was set to one 1.

    I also tried to activate to automatically lunch the chrome (like it works in phpstorm), it launch chrome but of some reason it don`t trigger the debug (Not sure why). I will investigate this more.