WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

A working .lando.yml file that allows enabling of xdebug, and also a launch.json and php.ini (if using WSL2)

Submitted by barnettech on Sat, 09/09/2023 - 18:01
name: example-xdebug
recipe: drupal9

config:
  webroot: .
  # Set Xdebug off by default. We use the tooling below to turn it on as needed.
  xdebug: false

services:
  appserver:
    overrides:
      environment:
        XDEBUG_MODE: 'debug,develop'

tooling:
  xdebug-on:
    service: appserver
    description: Enable Xdebug.
    user: root
    cmd:
      - docker-php-ext-enable xdebug && kill -USR2 $(pgrep -o php-fpm) > /dev/null || /etc/init.d/apache2 reload
      - tput setaf 2 && echo "Xdebug On" && tput sgr 0 && echo

  xdebug-off:
    service: appserver
    description: Disable Xdebug.
    user: root
    cmd:
      - rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && kill -USR2 $(pgrep -o php-fpm) > /dev/null || /etc/init.d/apache2 reload
      - tput setaf 1 && echo "Xdebug Off" && tput sgr 0 && echo

also here is the .vscode/launch.json (put it .vscode at the same level as .lando.yml)

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

https://github.com/AaronFeledy/lando-examples/blob/master/xdebug/.lando…

Using WSL2 in Windows I had to use this .vscode/php.ini

[PHP]
; Xdebug
xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
xdebug.mode = debug
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.client_port = 9003
xdebug.start_with_request = yes
xdebug.log = /tmp/xdebug.log
xdebug.idekey = "LANDO"

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

and then in my .lando.yml I had to have the additions to php.ini included in the config section (only needed if on Windows using WSL2):

name: fsrd-wm-web
recipe: drupal9
config:
  xdebug: false
  php: '8.1'
  webroot: web
  config:
    vhosts: config/local/apache2/default.conf
    php: .vscode/php.ini