Skip to content

Lando, VS Code and XDebug 3

Reference: GitHub Gist Correct settings for XDebug + VSCode + Lando (+3.0)

If you see an error/warning similar to Xdebug: [Step Debug] Could not connect to debugging client. Tried: 192.168.1.40:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(, this is good news. The debug configuration will probably work. :)

Lando & PHP & XDebug Versions

Lando v3.0.23

lando php -v

PHP 7.3.25 (cli) (built: Dec 11 2020 09:53:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.25, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.25, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v3.0.1, Copyright (c) 2002-2020, by Derick Rethans

Shared Files (php.ini and launch.json)

php.ini

[PHP]

; Xdebug
xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.log = /app/.vscode/xdebug.log

; Remote settings
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = ${LANDO_HOST_IP}
; xdebug.remote_connect_back = 1
xdebug.remote_log = /app/.vscode/xdebug_remote.log

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for XDebug (9003)",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "log": true,
      "pathMappings": {
        "/app/": "${workspaceRoot}/"
      }
    }
  ]
}

Lando Config for LAMP Recipe

.lando.yml

name: my-lando-lamp-app
recipe: lamp
config:
  database: mysql:5.7.32
  webroot: drupal/web
  php: "7.3"
  xdebug: debug
  config:
    php: .vscode/php.ini

Lando Config for Drupal 8 & 9 Recipe

Important! The regular custom configuration does not work. The .lando.yml file must not be configured like this

name: lando-d8-app
recipe: drupal8
config:
  database: mysql:5.7.32
  webroot: drupal/web
  php: "7.3"
  xdebug: true
  conf:
    php: scripts/lando-customizations/php.ini

Instead of the customizations like above, edit the file and move the customization to services node under appserver in the configuration for XDebug 3 to work.

Working .lando.yml file

name: lando-d8-app
recipe: drupal8
config:
  database: mysql:5.7.32
services:
  appserver:
    webroot: drupal/web
    php: "7.3"
    xdebug: debug
    config:
      php: scripts/lando-customizations/php.ini