localgovdrupal / localgov_project

Project template for Drupal 10 sites built with the LocalGov Drupal distribution.
https://localgovdrupal.org
GNU General Public License v2.0
10 stars 8 forks source link

Default configuration for xdebug and lando #97

Closed finnlewis closed 1 year ago

finnlewis commented 1 year ago

I find myself blowing away the entire project regularly for testing then manually setting up xdebug in lando and VSCode.

I would like to make this quicker.

My inclination is to:

  1. add some php.ini configuration to the default lando file
  2. enable xdebug by default
  3. include documentation for setting up xdebug on common IDEs (VSCode / PHP Storm... others?)

thoughts @ekes @stephen-cox ?

ekes commented 1 year ago

Don't know does this have the chance of slowing PHP down? Even if the XDEBUG_SESSION isn't set?

I have a .lando.local.yml that goes into all LocalGov Drupal projects that includes xdebug: true I got the impression I didn't even need to run docker-php-ext-enable with this recently.

finnlewis commented 1 year ago

It might slow PHP down a little, perhaps we should benchmark it to find out.

Even if it does, I think the amount of time it would save me and others regularly getting xdebug working would outweigh a little PHP performance hit.

finnlewis commented 1 year ago

@ekes what's in your .lando.local.yml ?

ekes commented 1 year ago

At the moment just

config:
  xdebug: true
  database: mariadb
finnlewis commented 1 year ago

Here's what works for me:

a .lando.local.yml file with the following:

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

a .lando/php.ini file with the following:

[PHP]

; Xdebug
xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
; Extra custom Xdebug setting for debug to work in VSCode.
xdebug.mode = debug
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.client_port = 9003
xdebug.start_with_request = trigger
xdebug.discover_client_host = true
xdebug.remote_connect_back = 1
xdebug.log = /app/xdebug.log
xdebug.idekey = lgd
html_errors = 1
ekes commented 1 year ago

For the record my lgd without any php.ini changes has these as default for the above:-

Directive => Local Value => Master Value
xdebug.max_nesting_level => 512 => 512
xdebug.show_exception_trace => Off => Off
xdebug.collect_params => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)

xdebug.mode => debug => debug
xdebug.client_host => 192.168.11.148 => localhost
xdebug.client_port => 9003 => 9003
xdebug.start_with_request => trigger => trigger
xdebug.discover_client_host => On => Off
xdebug.remote_connect_back => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.log => /tmp/xdebug.log => no value
xdebug.idekey => no value => no value
html_errors => Off => Off

Of which

$_ENV['XDEBUG_CONFIG'] => client_host=192.168.11.148 discover_client_host=1 log=/tmp/xdebug.log remote_enable=true remote_host=192.168.11.148

actually come from the settings lando makes in the environment variables.

So most of that is by lando, or is default, or is obsolete. Those that differ:

The max nesting level in the default is better I'd think? Drupal can go nesting crazy especially in the theme. But then if you have limited resources maybe making it smaller helps?

Then the other difference in your list is the xdebug.idekey which sounds very IDE specific, even down to if it cares about it https://xdebug.org/docs/all_settings#idekey

finnlewis commented 1 year ago

Good call @ekes - just tried without the php.ini changes and my debugging does work.

Maybe Lando has improved the defaults in recent years?

So I can now get debugging working with just the following in a .lando.local.yml:

config:
  xdebug: true

I wish it worked with the lando xdebug-on and lando xdebug-off commands, but it still seems I need to explicitly state xdebug: true then do a lando rebuild to get the breakpoints triggering.

finnlewis commented 1 year ago

I'm still not getting consistent results with Lando.

I'm having much more joy with DDEV, so I've created some docs for that instead: https://github.com/localgovdrupal/docs/pull/167

stephen-cox commented 1 year ago

XDebug just seems to work with PHPStorm

I do have a .lando.local.yml, but XDebug works with a web browser without it. It doesn need some setting up to work in a terminal session.

name: localgov-2.x
config:
  php: '8.1'
proxy:
  mailhog:
    - mail.localgov-2.x.lndo.site
  adminer:
    - adminer.localgov-2.x.lndo.site
services:
  appserver:
    xdebug: true
    config:
      php: .vscode/php.ini
    overrides:
      environment:
        DRUSH_OPTIONS_ROOT: '/app/web'
        DRUSH_OPTIONS_URI: 'https://localgov-2.x.lndo.site'
        PHP_IDE_CONFIG: "serverName=appserver"
finnlewis commented 1 year ago

It is working again for me now without any custom php.ini!

I'd still be interested to know what's in you php.ini @stephen-cox

stephen-cox commented 1 year ago

The php.ini looks pretty similar to the one you give above

[PHP]

; Xdebug
xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
; Extra custom Xdebug setting for debug to work in VSCode.
xdebug.mode = debug
xdebug.client_host = ${LANDO_HOST_IP}
xdebug.client_port = 9003
xdebug.start_with_request = trigger
; xdebug.remote_connect_back = 1
xdebug.log = /tmp/xdebug.log
finnlewis commented 1 year ago

Cool, so I reckon the defaults in Lando cover our needs, @stephen-cox I'd be interested to know if your debugging works without the custom php.ini, I'm expecting it will.

I'll add to the docs site to help people set up xdebug with VSCode. Maybe we could add a PHPStorm version too.

finnlewis commented 1 year ago

Here's the docs for setting up xdebug with DDEV: https://docs.localgovdrupal.org/devs/getting-started/debugging-with-xdebug.html

And I've just added to it with steps for Lando: https://github.com/localgovdrupal/docs/pull/169 / https://deploy-preview-169--inspiring-euclid-d918c8.netlify.app/devs/getting-started/debugging-with-xdebug.html#lando-xdebug-and-vscode