Skip to content

Instantly share code, notes, and snippets.

@danny-englander
Forked from miloskroulik/xdebug_lando_phpstorm.md
Last active October 29, 2024 09:47
Show Gist options
  • Save danny-englander/f55f1b623c17f537ab953a3c89162888 to your computer and use it in GitHub Desktop.
Save danny-englander/f55f1b623c17f537ab953a3c89162888 to your computer and use it in GitHub Desktop.
How to setup xdebug + Lando + PHPstorm when using Drupal 8/9 recipe

This assumes you are using a Drupal 8 or Drupal 9 recipe and Mac 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:7.4
    overrides:
      environment:
        PHP_IDE_CONFIG: "serverName=appserver"      

and .lando/php.ini file like this:

[PHP]
memory_limit = -1
max_execution_time = 90
post_max_size = 100M
upload_max_filesize = 100M

[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

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

  • Include paths: /home/<user>/.lando/config/drupal8 PHP > Servers:
  • check "Use path mappings" and add these mappings:
    • <local/project/path> -> /app
    • web -> /app/web
@danny-englander
Copy link
Author

ahh, good catch! Thanks.

@brooke-heaton
Copy link

Yea, hopefully someone who encounters that issue finds this thread! :)

@miloskroulik
Copy link

I updated my version over at https://gist.github.com/miloskroulik/ce76877a8a8e8fc8eec97a2e295e4864 based on my recent experience. Have a look if you have a trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment