Skip to content

xdebug with Lando and VSCode

Finn Lewis edited this page May 26, 2021 · 2 revisions

If you are using VSCode https://code.visualstudio.com/ and you want to step debug PHP owith xdebug, there are few steps to get set up.

1. Override the .lando.dist.yml file to a .lando.yml

See https://github.com/localgovdrupal/localgov_project/blob/2.x/.lando.dist.yml

In your project root:

cp .lando.dist.yml .lando.yml

2. specify a new local php.ini to override config

Edit .lando.yml to add the following lines unser services: appserver

    config:
      php: .vscode/php.ini

So that it now reads:

services:
  appserver:
    config:
      php: .vscode/php.ini
    overrides:
      environment:
        DRUSH_OPTIONS_ROOT: '/app/web'
        DRUSH_OPTIONS_URI: 'https://localgov-d9.lndo.site'
        SIMPLETEST_DB: 'mysql://database:database@database/database'
        MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", { "chromeOptions": { "w3c": false } }, "http://chromedriver:4444/wd/hub"]'

3. Create the override file

    nano .vscode/php.ini

with the following content:

[PHP]

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

4 Rebuild lando

lando rebuild

5. In VSCode, create a launch.json with the following content:

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

Note, to create a launch.json, click on the bug/triangle icon in the left navigation bar, then on the setting cog next to 'Listen for XDebug'.

Once created, you should be able to click the 'play' button tio the left of 'Listen for XDebug' to start debugging.

For more background, see https://docs.lando.dev/guides/lando-with-vscode.html