Search code examples
phpdockerdocker-composexdebugwindows-subsystem-for-linux

xDebug not working using docker, vscode and WSL 2


I am not sure what the issue is, it just doesn't work.

The routing seems to work, I have a server name in my nginx conf file. e.g. test.com. that works.

My project is in the root of ubuntu and not in the mount folders.

I am not sure what else to try.

xdebug.ini

[XDebug]
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so

xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_port=9002
xdebug.remote_handler=dbgp
xdebug.remote_connect_back=0
xdebug.remote_host=soapboxtest.com
xdebug.idekey=VSCODE
xdebug.remote_autostart=1
xdebug.remote_log=/usr/local/etc/php/xdebug.log

launch.json

{
  "name": "Listen for XDebug",
  "type": "php",
  "request": "launch",
  "port": 9002,
  "log": true,
  "externalConsole": false,
  "pathMappings": {
    "/var/www": "${workspaceRoot}"
  },
  "ignore": [
    "**/vendor/**/*.php"
    ]
  },

Request cookies

"XDEBUG_SESSION" => "VSCODE"

Dockerfile

FROM php:fpm-alpine3.11
...
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
...

Solution

  • This happened to me also and found that XDEBUG is not looking for the Docker Daemon Host. Got it fixed by adding:

    "hostname": "0.0.0.0"
    

    As part of the general options of the launch.json on VS Code.


    Full example:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "XDebug",
                "type": "php",
                "request": "launch",
                "hostname": "0.0.0.0",
                "port": 9000,
                "pathMappings": {
                    "/var/www/html/": "${workspaceFolder}"
                },
                "xdebugSettings": {
                    "max_children": 999,
                    "max_data": -1,
                }
            }
        ]
    }