I managed to make it working.
So, the idea is to setup two environment variables:
PHP_IDE_CONFIG="serverName=localhost"
, where localhost
is the name of the server in your PhpStorm settings.
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.