Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Xdebug for PHP

Using Xdebug for PHP allows developers to debug PHP-processes by connecting interactively.

...

To enable Xdebug for PHP please contact our root360 customer service.

Xdebug Usage

When Xdebug is activated, you can connect to your Xdebug sessions by following these steps:

  1. On your bastion host, start the program xdebug-helper. This will start an xdebug proxy in the background and print out connection information.

  2. Run the printed SSH-command on your local workstation in another shell.

  3. Connect your Xdebug client to the debugger:

    • debug-proxy: localhost:9001

    • client-listen-port: use the randomly chosen port printed by xdebug-helper

    • IDE-Key: use one of the keys printed by xdebug-helper. Every role gets its own IDE-Key to allow full control of the debugging process.

Simple example with one role

On bastion host

Code Block
languagebash
$ xdebug-helper 

Starting xdebug proxy session (lasts 24h) ...
Access logs by running 'screen -r xdebug-proxy' (leave with <ctrl>+<a>+<d>)

Client-Listen-Port: 20184
Debug-Proxy:        localhost:9001
SSH-Command:        ssh -A -R 20184:localhost:20184 -L 9001:localhost:9001 <bastion-host>
Available IDE-Keys: <ide-key-role1>, <ide-key-role2>

$

On local workstation

  1. Connect using SSH, specifying client-listen-ports

    Code Block
    languagebash
    $ ssh -A -R 20184:localhost:20184 -L 9001:localhost:9001 <bastion-host>
  2. In another set of shells you can use dbgpClient to debug each role:

    Code Block
    languagebash
    $ curl -LO https://xdebug.org/files/binaries/dbgpClient
    $ chmod +x dbgpClient
    # register client with first role
    $ ./dbgpClient -f -r '<ide-key-role>' -y localhost:9001 -p 20184
    proxyinit | success
    
    Xdebug Simple DBGp client (0.2)Copyright 2019-2020 by Derick Rethans
    
    Waiting for debug server to connect on port 20184.

...

Code Block
languagebash
$ ./dbgpClient -f -u '<ide-key-role>' -y localhost:9001

Advanded Example with two roles

On bastion host

Code Block
languagebash
$ xdebug-helper 

Starting xdebug proxy session (lasts 24h) ...
Access logs by running 'screen -r xdebug-proxy' (leave with <ctrl>+<a>+<d>)

Client-Listen-Port: 20184
Debug-Proxy:        localhost:9001
SSH-Command:        ssh -A -R 20184:localhost:20184 -L 9001:localhost:9001 <bastion-host>
Available IDE-Keys: xdebug-fpm-web, xdebug-fpm-backend, xdebug-fpm-frontend

$

On local workstation

  1. Connect using SSH specifying two client-listen-ports (you can choose any port you like, e.g. 20184 and 20185 in this example):

    Code Block
    languagebash
    $ ssh -A -R 20184:localhost:20184 -R 20185:localhost:20185 -L 9001:localhost:9001 <bastion-host>
  2. In another set of shells, you can use dbgpClient to debug each role:

    • connect to role backend:

    Code Block
    languagebash
    $ curl -LO https://xdebug.org/files/binaries/dbgpClient
    $ chmod +x dbgpClient
    # register client with first role
    $ ./dbgpClient -f -r 'debug-backend' -y localhost:9001 -p 20184
    proxyinit | success
    
    Xdebug Simple DBGp client (0.2)Copyright 2019-2020 by Derick Rethans
    
    Waiting for debug server to connect on port 20184.
    • connect to role frontend:

    Code Block
    # register client with second role
    $ ./dbgpClient -f -r 'debug-frontend' -y localhost:9001 -p 20185
    proxyinit | success
    
    Xdebug Simple DBGp client (0.2)Copyright 2019-2020 by Derick Rethans
    
    Waiting for debug server to connect on port 20185.

...

Code Block
languagebash
$ ./dbgpClient -f -u 'xdebug-backend' -y localhost:9001
$ ./dbgpClient -f -u 'xdebug-frontend' -y localhost:9001

Screencast using PhpStorm (Simple Example)

We have prepared a PhpStorm screencast illustrating how to set up xdebug (download).

...