1

I'm trying to setup CLI Xdebug in the Lando environment. It works flawlessly from the web, but I can't manage to make it working from CLI to debug tests and scripts.

Here is my .lando.yml file:

name: develop
recipe: wordpress
proxy:
  appserver_nginx:              
    - develop.loc

config:
  php: '7.3'
  via: nginx
  database: mariadb
  xdebug: true

I use PHPStorm as my IDE. I already setup server, server mapping, and ports 9000 and 9003 for listening, but it still doesn't stop at breakpoints. Did anyone setup CLI Xdebug with Lando? Any ideas? Thanks for helping.

Sergiy Zaharchenko
  • 1,490
  • 1
  • 12
  • 11

1 Answers1

2

I managed to make it working. So, the idea is to setup two environment variables:

  1. PHP_IDE_CONFIG="serverName=localhost", where localhost is the name of the server in your PhpStorm settings.

  2. XDEBUG_TRIGGER="1" - this variable triggers the xdebug.

But how can we provide the variables dynamically to make XDEBUG_TRIGGER working only when you want to?

For such things Lando has the tooling option! So, we can create the custom command which would make the magic happen, like this:

tooling:
  phpdebug:
    service: appserver
    cmd:
      - php
    env:
      XDEBUG_TRIGGER: 1
      PHP_IDE_CONFIG: "serverName=localhost"

Then restart (or rebuild) you appserver, and you'll have a brand new custom command for debugging PHP from CLI, like this:

lando phpdebug test.php

So, it works the same as lando php test.php, but with providing all the environment variables needed to run Xdebug.

Update: If someone is interested in how to debug WP CLI from the Lando environment:

lando phpdebug /app/vendor/wp-cli/wp-cli/bin/../php/boot-fs.php --version

So, it's the same as lando wp --version, but with providing Xdebug environment variables

P.S. Please be aware - it's the instructions for Xdebug 3.

Sergiy Zaharchenko
  • 1,490
  • 1
  • 12
  • 11