D8 D7 Debugging - pierregermain/MyDrupal GitHub Wiki

PREELIMINARES

  • Antes de nada: Apaga el firewall por si las moscas!
  • Activa suggestions desde el settings / services

XDEBUG en Devilbox usando Phpstorm

Para configurar XDEBUG 3 en PHPSTORM hay que ir comprobando pasito a paso cada opción de configuración.

Si falla mirar esto:

  • Este link te explica paso a paso lo que hay que hacer en PHPSTORM: https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html#on_demand_mode
  • Es importante crear en el root un fichero info.php y que se pueda cargar desde la web. Primero meter ahí el breakpoint. En dicha página web ver bien las configuraciones que se están usando
  • Ver bien si podemos usar las siguientes opciones (en xdebug 3.1 NO se deben de activar)
  • Enable return function value debugging
  • Ignore external connections

Desde Settings

  1. Desde File > Settings > PHP seleccionar

    • PHP 7.4
    • CLI Interpreter: (no interpreter)
  2. Desde File > Settings > PHP > Debug

    • Seguir los 4 pasos.
    • Debug Port: 9000 (no usar 9003 con devilbox)
    • Al hacer el validation script (no es obligatorio hacerlo) usar los siguientes datos:
      • Path to script: /home/pierre/webapps/devilbox/data/www/drupal-9/web
      • Url: http://drupal-9.loc
        Te dirá las cosas que te faltan. En mi caso me dice que debo usar "172.16.238.1" para la variable xdebug.client_host
  3. Desde File > Settings > PHP > Debug > DBGp Proxy usar lo siguiente:

    • IDE KEY : PHPSTORM
    • Host: 0.0.0.0
    • Port: 9000
  4. Desde *File > Settings > PHP > Servers * creamos un nuevo Server (no siempre hace falta, hay veces que el propio IDE al reconocer la llamada te lo autorellena)

    • Host: drupal-9.loc
    • Port: 80
    • Debugger: Xdebug
    • Relacionamos Path Mapping (esto es muy importante hacerlo bien): /home/pierre/webapps/devilbox/data/www/drupal-9/web /shared/httpd/drupal-9/web

Desde Configuration Settings en el menú de xdebug:

No hace falta crear ninguna configuración. Toma la de por defecto creada en el Settings general.

Php.ini del devilbox (en la máquina local (Host))

En cuanto al php.ini he usado estos datos:

; Configuraciones para xdebug 3

xdebug.mode = debug,profile
xdebug.start_with_request = yes
xdebug.client_port = 9000
xdebug.idekey = PHPSTORM
xdebug.log = /var/log/php/xdebug.log

;No hace falta (al menos usando MYIP en pasos posteriores)
;xdebug.client_host = 172.16.238.1
;xdebug.client_host = 192.168.1.134

Script de levantado

#!/bin/sh
#sudo service apache2 stop # tengo apache local
#sudo service mysql stop # tengo mysql local

# Obtener la IP de mi máquina (no se si hace falta)
export MYIP=$(ip route get 1 | sed 's/^.*src \([^ ]*\).*$/\1/;q')
echo $MYIP
cd ~/webapps/devilbox
cp env74 .env
docker-compose up mysql httpd php bind

En macOS:

ifconfig en0 | grep inet | awk '$1=="inet" {print $2}'

Modificaciones en el docker-compose

No se si haga falta, pero añade variable DEBUG y IP del host (mi máquina local)

services:
  php:
    environment:
      - XDEBUG_CONFIG=client_host=${MYIP}
      - DEBUG=1


Mas info vieja en:

https://github.com/pierregermain/MyDrupal/wiki/IDE-INTEGRATION-with-VAGRANT

En la documentación de devilbox dicen que hay que hacer redirects usando ssh -i que a mi nunca me ha echo falta.


XDEBUG en Netbeans contra servidor remoto

Abrimos un túnel haciendo

sshpass -p your-password ssh -p2220 your-user@your-remote-host -R 9002:127.0.0.1:9002

Visual Studio y XDEBUG


Debug themes

https://www.drupal.org/docs/7/theming/overriding-themable-output/working-with-template-suggestions

Debuggear el instalador de un módulo.

Es práctico usar mensajes del tipo:

  drush_log('Valor Variable: '.$variable, 'warning');

Instalar e desinstalar de la siguiente forma el módulo:

clear;drush cc all; drush en -y NOMBRE_MODULO;drush cc all;
clear;drush cc all; drush pm-disable -y NOMBRE_MODULO;drush pm-uninstall -y NOMBRE_MODULO;