Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Xdebug 3 #2718

Closed
rabauss opened this issue Dec 1, 2020 · 56 comments
Closed

Support Xdebug 3 #2718

rabauss opened this issue Dec 1, 2020 · 56 comments
Assignees
Labels
feature Requesting that Lando do something new

Comments

@rabauss
Copy link
Contributor

rabauss commented Dec 1, 2020

Xdebug 3 is out and comes with a lot of performance optimization - see: https://xdebug.org/announcements/2020-11-25

I'm not sure which PHP Images should get the Update - what do you think?
See the upgrade guide for all necessary steps: https://xdebug.org/docs/upgrade_guide

The Update also supports PHP 8, so it's related to: #2660

@rabauss rabauss added the feature Requesting that Lando do something new label Dec 1, 2020
@labboy0276
Copy link
Sponsor Contributor

Xdebug 3 is included with the newer docker images. If you do a lando rebuild, it should be there.

@rabauss
Copy link
Contributor Author

rabauss commented Dec 2, 2020

That's nice! But unfortunately the settings have to change:

XDEBUG_CONFIG: `remote_enable=true remote_host=${options._app.env.LANDO_HOST_IP}`,

Should get changed to:

 XDEBUG_CONFIG: `xdebug.mode=debug xdebug.client_host=${options._app.env.LANDO_HOST_IP}`, 

also the php.ini has to change or the XDEBUG_CONFIG has to be extended:

xdebug.remote_autostart = 1

xdebug.start_with_request = trigger

And in your IDE you have to change the xdebug port from 9000 to 9003!

see: https://xdebug.org/docs/upgrade_guide

In summary I added the following to my cutom php.ini

xdebug.mode = debug
xdebug.client_host = host.docker.internal
xdebug.start_with_request = trigger

@Tigatok
Copy link
Contributor

Tigatok commented Dec 2, 2020

@rabauss Trying to get this to work with a D8 recipe, how are you setting your php.ini file? Under appserver, or under the top-level config?

Update 1:

I have this working now with PHPStorm. Using @rabauss's answer I modified the following:

  • removed the duplicate xdebug.start_with_request = 1, and just had the xdebug.start_with_request = trigger.
  • Change host.docker.internal with ${LANDO_HOST_IP}.

I am using the Drupal 8 recipe, and my lando file (relevant infos) looks like this:

name: myapp
recipe: drupal8

config:
  php: '7.3'
  via: nginx
  webroot: web

services:
  appserver:
    type: php
    config:
      php: .lando/php.ini

And my ./lando/php.ini looks like:

xdebug.mode = debug
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.start_with_request = trigger

@rabauss
Copy link
Contributor Author

rabauss commented Dec 2, 2020

Oh, seems good to me!
It was too late for me this night and I did not see the obvious duplicate of xdebug.start_with_request

EDIT:
I guess the xdebug config needs a switch case for old php images!

@ds-santos
Copy link

ds-santos commented Dec 2, 2020

I try the @Tigatok solution in drupal 8 installation (Vscode) with no success :(

@labboy0276
Copy link
Sponsor Contributor

@pirog I can confirm @Tigatok solution works

@Tigatok
Copy link
Contributor

Tigatok commented Dec 2, 2020

I try the @Tigatok solution in drupal 8 installation (Vscode) with no success :(

Hi @ds-santos , I can probably try to assist you offline, but in efforts for internet documentation, can you confirm you followed the correct steps in regards to:

  • Setting xdebug in PHPStorm to be 9003 and not 9000
  • Ensure you have the proper php.ini file loading
  • Ensure xdebug is enabled on lando appserver (lando php -v)

@ds-santos
Copy link

ds-santos commented Dec 2, 2020

Hi @Tigatok, thanks for disponibility to help me :) , luckily I have already managed to make the wings work again

The configurations I have used for drupal 8 installation + vscode are:

/.vscode/launch.json

{
 "version": "0.2.0",
 "configurations": [
   {
     "name": "Listen for XDebug",
     "type": "php",
     "request": "launch",
     "port": 9003,
     "pathMappings": {
       "/app/": "${workspaceFolder}"
     }
   }
 ]
}

/.vscode/php.ini

[PHP]

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.start_with_request = yes

pirog added a commit that referenced this issue Dec 2, 2020
pirog added a commit that referenced this issue Dec 2, 2020
pirog added a commit that referenced this issue Dec 2, 2020
pirog added a commit that referenced this issue Dec 2, 2020
@pirog
Copy link
Sponsor Member

pirog commented Dec 2, 2020

Support for xdebug 2/3 will be in the next release, which should be out sometime in the next hour. here are the docs about how it will work
https://docs.lando.dev/config/php.html#using-xdebug

@pirog pirog closed this as completed Dec 2, 2020
@tsega
Copy link

tsega commented Dec 3, 2020

@ds-santos what does your .lando.yml file look like? I've used the following but Xdebug is now showing on phpinfo() page:

name: test
recipe: drupal8

config:
  webroot: web

services:
  appserver:
    type: php
    config:
      php: .vscode/php.ini

@anibalsanchez
Copy link
Contributor

For the record, the alternative Xdebug 3 configuration for VSCode / felixfbecker/vscode-php-debug:

xdebug.mode = debug
xdebug.start_with_request = yes

;; xdebug.client_host = ${LANDO_HOST_IP}
;; Alternative to avoid binding the IP
xdebug.discover_client_host = true

xdebug.client_port = 9099
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9099,

            "pathMappings": {
                "/app/www": "${workspaceRoot}/www"
            }
        },

Please, note that xdebug.start_with_request = trigger doesn't work on VSCode / felixfbecker/vscode-php-debug.

@ds-santos
Copy link

ds-santos commented Dec 3, 2020

@tsega My ."lando.yml"

name: drupal
recipe: drupal8
config:
  php: '7.4'
  via: apache
  database: mysql:5.7
  webroot: web
services:
  database:
    creds:
      user: XXXX
      password: XXXX
      database: database
  appserver:
    webroot: web
    xdebug: true
    config:
      php: .vscode/php.ini

@tsega
Copy link

tsega commented Dec 3, 2020

Thanks @ds-santos, I was missing that xdebug: true part. This is what my currently working setup looks like:

.lando.yml

name: d8
recipe: drupal8
config:
  webroot: web
services:
  appserver:
    type: php
    xdebug: true
    config:
      php: .lando/php.ini

.vscode/php.ini

[PHP]

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

.vscode/launch.json

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "port": 9003, // Notice: Default port changed to 9003
      "log": true,
      "pathMappings": {
        "/app/": "${workspaceFolder}",
      }
    }
  ]
}

@andreityuhai
Copy link

andreityuhai commented Dec 3, 2020

I there an option to force using xdebug 2 at lando, while version 3 is not officially supported?

@pirog
Copy link
Sponsor Member

pirog commented Dec 3, 2020

version 3 is officially supported as of the release last night
#2718 (comment)

@fmitchell
Copy link
Sponsor

fmitchell commented Dec 8, 2020

This worked for me PHPStorm 2020.3, drupal9, lando v3.0.21

name: foo
recipe: drupal9
config:
  webroot: ./web
  php: '7.4'

services:
  appserver:
    xdebug: true
    config:
      php: config/php.ini

config/php.ini

; php.ini file for use with lando locally
; to avoid out of memory errors
memory_limit = -1
; 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.start_with_request = yes

I also made sure to choose the right docker image in my CLI setup: https://www.evernote.com/l/AOyDM2RT8ENO5LfrAXKzbdL5kRft4k_BpW0

Optional: I also have this in my lando file to switch xdebug off and on:

tooling:
  xdebug-on:
    service: appserver
    description: Enable xdebug for apache.
    cmd: "docker-php-ext-enable xdebug && /etc/init.d/apache2 reload"
    user: root

  xdebug-off:
    service: appserver
    description: Disable xdebug for apache.
    cmd: "rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && /etc/init.d/apache2 reload"
    user: root

@tsega
Copy link

tsega commented Dec 8, 2020

@fmitchell that optional xdebug on/off is something I have been looking for. How do you use it?

@fmitchell
Copy link
Sponsor

@tsega lando xdebug-off will turn it off. When you want to use it again, lando xdebug-on. It is cribbed from: https://github.com/AaronFeledy/lando-examples/blob/master/xdebug/.lando.yml

His version handles whether your lando is apache2 or php-fpm

@tsega
Copy link

tsega commented Dec 8, 2020

This is awesome! 🔥

Since discovering how Drupal's performance is hit so badly when xdebug is enabled, I've been looking for such a command to enable/disable it with minimum fuss.

Thanks again!

@Tigatok
Copy link
Contributor

Tigatok commented Dec 11, 2020

For nginx, the tooling is similar

tooling:
  xdebug-on:
    service: appserver
    description: Enable xdebug for nginx.
    cmd: docker-php-ext-enable xdebug && pkill -o -USR2 php-fpm
    user: root
  xdebug-off:
    service: appserver
    description: Disable xdebug for nginx.
    cmd: rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && pkill -o -USR2 php-fpm
    user: root

@generalredneck
Copy link
Contributor

wanna throw out there that the documentation is still lagging behind over at https://docs.lando.dev/guides/lando-with-vscode.html#debugging-phpunit

@juampynr
Copy link

I ended up having to do a mix of #2741 plus feedback provided here in order to get it working at PHPStorm (even for Drush commands):

lando v3.0.23

.lando.yml

services:
  appserver:
    xdebug: true
    config:
      php: .lando/php.ini
    overrides:
      environment:
        PHP_IDE_CONFIG: "serverName=appserver"

.lando/php.ini

[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

@uberhacker
Copy link
Contributor

@juampynr: Nice! I can confirm this works.

@jaybabak
Copy link
Contributor

jaybabak commented Dec 29, 2020

For VSCODE
Port needs to default to 9000 to work with the xdebug extension using the following:
xdebug.client_port=9000

For XDebug v3.x.x:

xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000

For XDebug v2.x.x:

xdebug.remote_enable = 1
xdebug.remote_autostart = 1

Reference:
https://github.com/xdebug/vscode-php-debug

@zahardev
Copy link

zahardev commented Jan 5, 2021

Now the default Xdebug port is 9003 - https://xdebug.org/docs/upgrade_guide#Step-Debugging. So for me just changing the debug port in IDE to 9003 fixed the problem.

@jnfDev
Copy link

jnfDev commented Jan 30, 2021

Unable to configure Lando with Xdebug 3 and WSL2. Version 2 of Xdebug works fine, but this new one was impossible to configure out. I need help, here my current configuration:

php.ini

[PHP]
; 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.start_with_request = yes

.lando.yml

name: my-wpsite
recipe: wordpress
services:
  appserver:
    webroot: .
    xdebug: true
    config:
      php: .vscode/php.ini
    overrides:
      environment:
        LANDO_HOST_IP: host.docker.internal

Here is my log:
image

Help 😢

@jnfDev
Copy link

jnfDev commented Jan 30, 2021

I there an option to force using xdebug 2 at lando, while version 3 is not officially supported?

Yes, you can do something like this:

services:
  appserver:
     #other-service's directives
     build_as_root:
      - pecl uninstall xdebug
      - pecl install xdebug-2.9.8

@rabauss
Copy link
Contributor Author

rabauss commented Jan 30, 2021

"Xdebug's default debugging port has changed from 9000 to 9003."
see: https://xdebug.org/docs/upgrade_guide#Step-Debugging

@tormi
Copy link
Contributor

tormi commented Feb 1, 2021

We have the following configuration for Xdebug 3, which introduces the lando xdebug tool. Modes (incl. profile) can be defined in the .lando/php.ini file, default value is debug. lando xdebug off turns Xdebug off. Changing modes doesn't require lando rebuild.

.lando.yml

config:
  xdebug: false
  config:
    php: .lando/php.ini

services:
  appserver:
    overrides:
      environment:
        XDEBUG_MODE:
        PHP_IDE_CONFIG: "serverName=appserver"

tooling:
  xdebug:
    description: Loads Xdebug in the mode defined in the .lando/php.ini file. Run `lando xdebug off` to turn Xdebug off.
    cmd:
      - appserver: /app/.lando/xdebug.sh
    user: root

.lando/php.ini

; Valid Xdebug modes: https://xdebug.org/docs/all_settings#mode.
xdebug.mode = debug

.lando/xdebug.sh

#!/bin/bash

if [ "$#" -ne 1 ]; then
  docker-php-ext-enable xdebug
  pkill -o -USR2 php-fpm
  echo "Xdebug is loaded in the mode defined in the .lando/php.ini file."
  echo "Valid modes: https://xdebug.org/docs/all_settings#mode."
else
  rm -rf /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
  pkill -o -USR2 php-fpm
  echo "Xdebug is turned off."
fi

.vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for XDebug (9003)",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "log": true,
      "pathMappings": {
        "/app/": "${workspaceRoot}/"
      }
    }
  ]
}

@tormi
Copy link
Contributor

tormi commented Feb 1, 2021

Waiting for the feedback for my proposal here to get things even easier: #1668 (comment)

It would allow to load Xdebug modes on the fly via lando xdebug <mode(s)>, f.ex lando xdebug debug,develop.

@Tigatok
Copy link
Contributor

Tigatok commented Feb 2, 2021

@jnfDev Did you ever figure out your WSL2 stuff?

@tormi
Copy link
Contributor

tormi commented Feb 4, 2021

Waiting for the feedback for my proposal here to get things even easier: #1668 (comment)

It would allow to load Xdebug modes on the fly via lando xdebug <mode(s)>, f.ex lando xdebug debug,develop.

This is working now: #1668 (comment).

@brandonratz
Copy link

@Tigatok I have WSL2 working w/ PHP Storm with the following

Changed port in IDE to 9003

/app/php.ini

;Xdebug2
xdebug.max_nesting_level=256
xdebug.show_error_trace=1
xdebug.show_exception_trace=0
xdebug.collect_params=3
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_host=${LANDO_HOST_IP}
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.var_display_max_children=3
;xdebug.remote_log=/app/xdebug.log

;Xdebug3
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 = /app/xdebug.log

I left my Xdebug2 settings in the ini as they don't seem to cause any conflict

Note: I also have in .lando.yml

appserver:
  overrides:
    environment:
      LANDO_HOST_IP: "host.docker.internal"
      XDEBUG_CONFIG: "remote_enable=1 remote_host=host.docker.internal"

I am just now fixing this with Xdebug3 so I don't know if some of my past settings are irrelevant. I was able to add those Xdebug3 settings to my php.ini and get it working.

@tormi
Copy link
Contributor

tormi commented Feb 9, 2021

@brandonratz , I'm on Mac and the only thing needed from the above for Xdebug 3 setup is xdebug.start_with_request = yes and even that's only if using PhpStorm.

Could you to try out this recipe and report back if it's working with WSL2: #1668 (comment)?

@brandonratz
Copy link

@tormi I added the following to .lando.yml

tooling:
  xdebug-on:
    service: appserver
    description: Enable xdebug for nginx.
    cmd: docker-php-ext-enable xdebug && pkill -o -USR2 php-fpm
    user: root
  xdebug-off:
    service: appserver
    description: Disable xdebug for nginx.
    cmd: rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && pkill -o -USR2 php-fpm
    user: root
❯ lando xdebug-on
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(

warning: xdebug (xdebug) is already loaded!
❯ lando xdebug-off
rm: cannot remove '/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini': No such file or directory

@tormi
Copy link
Contributor

tormi commented Feb 11, 2021

@brandonratz , there's a readme part as well in that recipe. Try using lando xdebug <mode> instead of lando xdebug-on / off.

EDIT: Just noticed you're not using the recipe I've referred at all. This is the comment I was referring to earlier: #1668 (comment)

@brandonratz
Copy link

@tormi My apologies, the link to your comment bugged out when I initially clicked on it.

I can confirm your shell script and tooling setup work in my WSL2 environment!

@Tigatok
Copy link
Contributor

Tigatok commented Feb 16, 2021

It appears to me that it is very inconsistent. I sometimes have to reboot my machine and lando rebuild multiple times before Xdebug will work.

I think this is a port/ip networking related issue where perhaps some times things pick up and sometimes they don't? Anyone with a similar experience?

@tormi
Copy link
Contributor

tormi commented Feb 16, 2021

It appears to me that it is very inconsistent.

@Tigatok, are you referring to #1668 (comment) recipe?

@Tigatok
Copy link
Contributor

Tigatok commented Feb 16, 2021

It appears to me that it is very inconsistent.

@Tigatok, are you referring to #1668 (comment) recipe?

Ah sorry I should have been clear. The entire thread (and many others online) in terms of getting the Xdebug in the container to listen seems to be inconsistent. Specifically which part, I am not 100% sure. That being said I trust the tooling you have in your comment is working just fine.

@maskedjellybean
Copy link

Just wanted to add that none of this worked for me with Xdebug 3 until I added to .lando.yml:

services:
  appserver:
    overrides:
      environment:
        XDEBUG_CONFIG: "client_host=host.docker.internal client_port=9003 start_with_request=yes log=/app/lando/logs/xdebug.log"
        XDEBUG_MODE: "debug"

The key to figuring it out was to look at phpinfo(). Although the Xdebug section matched what I had configured in php.ini, XDEBUG_CONFIG and XDEBUG_MODE did not. I'm assuming it was configuration coming from Lando. Apparently this takes priority over the Xdebug section?

@tormi
Copy link
Contributor

tormi commented Aug 10, 2021

@maskedjellybean - this didn't work for you? It allows switching Xdebug mode changes on the fly. Defining XDEBUG_MODE: "debug" means that it's always using debug mode.

@maskedjellybean
Copy link

@tormi Thank you! I saw your script and thought it was the same as the previous script so I didn't try it until now. It works!

Your script works great as is, but I made a few changes that will work better for me personally so I figure I should share. The differences are:

  • Set mode to debug if no mode is passed. This is the mode I'll use 99% of the time.
  • Allow passing "off" to truly disable xdebug. If "off", run rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && pkill -o -USR2 php-fpm. I pulled this from the previous script. I'm no expert, but what I do know is that after this is run, lando php -v no longer reports Xdebug as being loaded. Without this Xdebug is always reported as loaded.
  • Add pretty colors.
if [ "$#" -ne 1 ]; then
  echo xdebug.mode = debug > /usr/local/etc/php/conf.d/zzz-lando-xdebug.ini
  docker-php-ext-enable xdebug && pkill -o -USR2 php-fpm
  php -v
  echo && tput setaf 2 && echo "Xdebug is loaded in debug mode." && tput sgr 0 && echo
  echo "To load in a different mode, follow the syntax: 'lando xdebug <mode>'."
  echo "Valid modes: https://xdebug.org/docs/all_settings#mode."
elif [ "$1" = "off" ]; then
  echo xdebug.mode = off > /usr/local/etc/php/conf.d/zzz-lando-xdebug.ini
  rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && pkill -o -USR2 php-fpm
  php -v
  echo && tput setaf 1 && echo "Xdebug has been turned off." && tput sgr 0 && echo
else
  mode="$1"
  echo xdebug.mode = "$mode" > /usr/local/etc/php/conf.d/zzz-lando-xdebug.ini
  docker-php-ext-enable xdebug && pkill -o -USR2 php-fpm
  php -v
  echo && tput setaf 2 && echo "Xdebug is loaded in "$mode" mode." && tput sgr 0 && echo
fi

Thanks again!

@smustgrave
Copy link

Seems a lot of people tried different things. Wondering if anyone could share their lando and php.ini they used that worked for them

@anibalsanchez
Copy link
Contributor

This is my php.ini for Lando and VS Code:

xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = true

@smustgrave
Copy link

Using phpstorm tried that but i get

Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(

And my xdebug port is set to 9003 in phpstorm.

@anibalsanchez
Copy link
Contributor

You may have to add the port definition in the php.ini:

xdebug.client_port = 9003

@smustgrave
Copy link

So this is the php.ini file I'm trying
xdebug.idekey=PHPSTORM
xdebug.max_nesting_level = 1024
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
xdebug.mode = debug
xdebug.client_host = 10.0.2.2
xdebug.client_port = 9003
xdebug.start_with_request = yes
xdebug.file_link_format=phpstorm://open?%f:%l
xdebug.discover_client_host=1

@UrielArenas
Copy link

I ended up having to do a mix of #2741 plus feedback provided here in order to get it working at PHPStorm (even for Drush commands):

lando v3.0.23

.lando.yml

services:
  appserver:
    xdebug: true
    config:
      php: .lando/php.ini
    overrides:
      environment:
        PHP_IDE_CONFIG: "serverName=appserver"

.lando/php.ini

[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

How did you set up the launch.json in Vscode if I may ask?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Requesting that Lando do something new
Projects
None yet
Development

No branches or pull requests