Skip to content

Instantly share code, notes, and snippets.

@miloskroulik
Last active March 29, 2024 15:02
Show Gist options
  • Save miloskroulik/ce76877a8a8e8fc8eec97a2e295e4864 to your computer and use it in GitHub Desktop.
Save miloskroulik/ce76877a8a8e8fc8eec97a2e295e4864 to your computer and use it in GitHub Desktop.
How to setup xdebug + Lando + PHPstorm when using Drupal 8 recipe

I assume you're using Drupal 8 recipe and Linux as a host OS. Also, xdebug 3.x is assumed, which is standard for Lando-provided PHP image.

Set up Lando

Example .lando.yml file can look like this:

name: xdebug-test
recipe: drupal8
config:
  webroot: web
services:
  appserver:
    xdebug: true
    config:
      php: .lando/php.ini
    type: php:8.2
    overrides:
      environment:
        PHP_IDE_CONFIG: "serverName=appserver"      

Custom php.ini

Create .lando/php.ini file like this:

[PHP]
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

Note

It looks like this is no longer needed, default php.ini works fine now.

Set up PHPStorm

Standard setup should be followed (CLI interpreter setup using docker, xdebug remote port 9003. However, xdebug is not detected automatically. Fix it by running:

  • lando ssh -s appserver -u root
  • and find / -name '*xdebug.so'inside of the container

It will give you a path which needs to be added to the bottom of PHPStorm CLI interpreter settings as a path to xdebug. It should be similar to: /usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so. Then reload found CLI interpreter and xdebug should be found.

Furthermore, in one of my projects I needed to add these settings, so that path mappings are working:

PHP > Path mappings

  • /your/lando/project/path -> /app
    • /your/lando/project/path/web -> /app/web

PHP > Servers:

Add "server" for each of your lando hostnames

Ceck "Use path mappings" and add a mapping:

  • /your/lando/project/path -> /app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment