Unable to get Xdebug working with Lando and VSCode. Connects and stops immediately

2.5k Views Asked by At

I have been through every post I can find on this subject but I can not find a solution. So instead of pulling my hair out more, I'll post a question.

I have a Lando install (running Drupal 8, but I'm testing on a simple phpinfo() script) with Xdebug confirmed to be running. Whenever I add a breakpoint and run the script it fails to stop.

custom Lando .ini for Xdebug:

[PHP]

Xdebug
xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
; Extra custom Xdebug setting for debug to work in VSCode.
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = "dbgp"
xdebug.remote_host = ${LANDO_HOST_IP}
xdebug.remote_connect_back = 0
xdebug.remote_mode = req
xdebug.remote_autostart = On
xdebug.remote_log = /tmp/xdebug.log
xdebug.idekey = VSCODE

max_execution_time = 0

Output of xdebug.log

245] Log opened at 2020-09-09 14:42:21
[245] I: Connecting to configured address/port: host.docker.internal:9000.
[245] I: Connected to client. :-)
[245] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///app/web/info.php" language="PHP" xdebug:language_version="7.3.22" protocol_version="1.0" appid="245" idekey="VSCODE"><engine version="2.9.6"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2020 by Derick Rethans]]></copyright></init>

[245] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

[245] Log closed at 2020-09-09 14:42:21

I had xdebug working without an issue in PhpStorm but no luck in VSCode.

1

There are 1 best solutions below

1
On

After the latest release v3.0.22**

which includes support for xdebug 3 you will need the xdebug: debug and config: php settings in your .lando.yml

services:
  appserver:
    webroot: web
    xdebug: debug
    config:
      php: .lando.php.ini

a .lando.php.ini file with

[PHP]
xdebug.mode=debug
xdebug.start_with_request = yes
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.log = /tmp/xdebug.log

and the vscode configuration in .vscode/launch.json with port: 9003

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Lando XDebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "log": false,
      "pathMappings": {
        "/app/": "${workspaceFolder}/",
      }
    }
  ]
}

Before and up to release v3.0.19

I was able to run lando xdebug with vscode using this configuration .vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Lando XDebug",
      "type": "php",
      "request": "launch",
      "port": 9000,
      "log": true,
      "pathMappings": {
        "/app/": "${workspaceRoot}/",
      }
    },
  ]
}

and I did not include any lando php.ini config in my .lando.yml

services:
  appserver:
    webroot: web
    xdebug: true
# no need for php.ini configuration
#    config:
#      php: .lando.php.ini

that the official xdebug actually instructs