Similar contents

Tag: Setup Xdebug with Lando and Drupal on Ubuntu Linux

Setup Xdebug with Lando and Drupal on Ubuntu Linux

Using Lando to setup the Xdebug to help you to create a lot of code :)

By

pablito

created on Wednesday, January 31, 2024 - 01:42AM - UTC

Content body

Begin by installing Xdebug in your terminal:

sudo apt-get install php-xdebug


Next, verify the installation, path, and port.
You can confirm this in many different ways, I usually use this one:

php -i | grep xdebug


You should have an output similar to this:

/etc/php/8.3/cli/conf.d/20-xdebug.ini
xdebug
Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support
             Enabled Features (through 'xdebug.mode' setting)
xdebug.auto_trace => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.cli_color => 0 => 0
xdebug.client_discovery_header => HTTP_X_FORWARDED_FOR,REMOTE_ADDR => HTTP_X_FORWARDED_FOR,REMOTE_ADDR
xdebug.client_host => localhost => localhost
xdebug.client_port => 9003 => 9003
xdebug.cloud_id => no value => no value
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)
xdebug.collect_params => On => On
xdebug.collect_return => Off => Off
xdebug.collect_vars => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)
xdebug.connect_timeout_ms => 200 => 200
xdebug.control_socket => time: 25ms => time: 25ms
xdebug.coverage_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.default_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.discover_client_host => Off => Off
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.gc_stats_output_dir => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => no value => no value
xdebug.log => no value => no value
xdebug.log_level => 7 => 7
xdebug.max_nesting_level => 512 => 512
xdebug.max_stack_frames => -1 => -1
xdebug.mode => develop => develop
xdebug.output_dir => /tmp => /tmp
xdebug.overload_var_dump => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.profiler_enable_trigger => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.profiler_enable_trigger_value => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.profiler_output_dir => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_autostart => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_connect_back => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_enable => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_host => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_log => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_log_level => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_mode => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_port => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.remote_timeout => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => (setting removed in Xdebug 3) => (setting removed in Xdebug 3)
xdebug.start_upon_error => default => default
xdebug.start_with_request => default => default
xdebug.trace_enable_trigger => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.trace_enable_trigger_value => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => (setting renamed in Xdebug 3) => (setting renamed in Xdebug 3)
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.trigger_value => no value => no value
xdebug.use_compression => 0 => 0
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3


Navigate to xdebug.ini file, in this case the path is: /etc/php/8.3/cli/conf.d/20-xdebug.ini


Update like this one:

zend_extension=xdebug.so
; Xdebug
xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
xdebug.mode = debug
xdebug.start_with_request = trigger
xdebug.client_host = 127.0.0.1
xdebug.log = /tmp/xdebug.log

; Remote settings
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = ${LANDO_HOST_IP}
xdebug.remote_connect_back = 1
xdebug.remote_log = /tmp/xdebug_remote.log



Now check the correct version of xdebug to your PHP:

php-config --extension-dir


In my case using the PHP 8.3 the extensions are: /usr/lib/php/20230831


Now, integrate this information into php.ini.
Choose between two options: 
1) Add to local installation at path: etc/php/8.3/cli/php.ini 
2) Create a php.ini for your lando.yml project:

config:
  php: '8.3'
  config:
    php: .lando/php.ini



Take note of your PHP extension version and port, as they may vary between environments.
Include the following lines in your php.ini:

xdebug.show_local_vars=1
zend_extension=/usr/lib/php/20230831/xdebug.so
xdebug.mode=debug,coverage
xdebug.start_with_request=trigger
xdebug.client_port=9003
xdebug.client_host=127.0.0.1
xdebug.log=/var/log/xdebug.log

 

You probably already have an environment working and to make it more clearly I just add the lines related to Xdebug setup.
Update your lando.yml with the config and debug tooling

config:
  xdebug: 'coverage, debug'

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

You don't need to run the command lando xdebug-on every time that you restart your containers, but sometimes you want to turn off to get more speed.


Rebuild your lando to update with the Xdebug config and tooling

lando rebuild -y


And the last but not least, setup your IDE.
I'm using VSCODE, my example is something like this:

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Listen for Xdebug (Local)",
        "type": "php",
        "request": "launch",
        "port": 9003,
        "log": true,
        "pathMappings": {
          "/app/": "${workspaceRoot}/"
        },
        "xdebugSettings": {
          "max_children": 128,
          "max_data": 1024,
          "max_depth": 3,
          "show_hidden": 1
        }
      },
      {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9003,
        "xdebugSettings": {
          "max_children": 128,
          "max_data": 1024,
          "max_depth": 3,
          "show_hidden": 1
        }
      }
    ]
  }


That's all!!!

 

More content for you

Join the conversation

Texto puro

  • Nenhuma tag HTML permitida.
  • Quebras de linhas e parágrafos são feitos automaticamente.
  • Endereços de página da web e endereços de e-mail se tornam links automaticamente.
keyboard_arrow_up