3

I am trying to enable xdebug on Lando using the pantheon recipe. I have tried different tutorials, but PHPStorm does not seem to connect to Lando, or xdebug is not correctly enabled on Lando.

recipe: pantheon
config:
  framework: drupal8
  xdebug: true

Have some of you had this issue?

2
  • This question probably needs to go to the lando issue queue or Stack Overflow. Setting up the xdebug connection between PHPStorm and Lando is a PHP issue and isn't specific to Drupal. That said, the absolute requirement for getting xdebug working with PHPStorm in Lando is to make sure you have set the lando docker container PHP as the CLI interpreter in the PHPStorm settings. From there, it's a bit of trial-and-error and depends on the versions of lando, PHP, and PHPStorm. Commented Aug 8, 2022 at 7:36
  • I am able to setup xdebug on a Lando environemnt, the problem is when I am using the pantheon recipe for Drupal. Commented Aug 8, 2022 at 8:16

2 Answers 2

4

The answer from @no-sssweat works great. Even so, many of those settings can be removed, and you can set up tooling so xdebug isn't always running (and slowing down your local testing). This is based on the lando github issue "Allow faster xdebug on/off toggling":

.lando.yml

recipe: pantheon
config:
  framework: drupal8
  xdebug: off
  config:
    php: .lando.php.ini
services:
  appserver:
    overrides:
      environment:
        XDEBUG_MODE:
tooling:
  xdebug-on:
    service: appserver
    description: Enable xdebug for nginx
    cmd:
      - echo "[INFO] Enabling xdebug ..."
      - echo xdebug.mode = "debug,develop" > /usr/local/etc/php/conf.d/zzz-lando-xdebug.ini
      - pkill -o -USR2 php-fpm
    user: root
  xdebug-off:
    service: appserver
    description: Disable xdebug for nginx
    cmd:
      - echo "[INFO] Disabling xdebug ..."
      - echo xdebug.mode = "off" > /usr/local/etc/php/conf.d/zzz-lando-xdebug.ini
      - pkill -o -USR2 php-fpm
    user: root

(yes, you need XDEBUG_MODE in there so that you can override the value, and yes, start with it off so that it doesn't enable debugging by default)

.lando.php.ini

; Xdebug settings required for PhpStorm.
xdebug.start_with_request=yes

Then leave PhpStorm listening all the time and just run the tooling:

>lando xdebug-on
>lando xdebug-off
2
  • Very nice! Thanks for sharing! I will certainly add this to the tooling so I don't have to rebuild every time to turn on and off and update the overrides environment as you mentioned.
    – No Sssweat
    Commented Jun 6, 2023 at 23:15
  • Thanks for the boost! It was your answer that helped me get this in the first place!
    – Eric Woods
    Commented Jun 7, 2023 at 15:13
2

Note: While my answer works, @Eric Woods answer is superior.


Ever since Xdebug 3 came out, I've had to use a .lando.php.ini file in order for it to work with Lando.

recipe: pantheon
config:
  framework: drupal8
services:
  appserver:
    type: php
    xdebug: true
    config:
      php: .lando.php.ini
    overrides:
      environment:
        PHP_IDE_CONFIG: "serverName=appserver"
        LANDO_HOST_IP: "host.docker.internal"
        XDEBUG_CONFIG: "remote_enable=1 remote_host=host.docker.internal"

In the project's root folder, create a .lando.php.ini

.lando.php.ini

; 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.client_port = 9003
xdebug.start_with_request = yes

In your PHP storm settings, create the "appserver" by hitting the "+" icon. Make sure you add the /app path to the root.

enter image description here

Note: Replace Host with your actual host name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.