Xdebug for PHP
Using Xdebug for PHP allows developers to debug php-processes by connecting interactively.
This allows setting breakpoints, changing content and reviewing stack traces.
We support the usage of xdebug by installing and configuring the required packages on the PHP-servers.
To allow remote debugging we’ll install a Xdebug proxy on the bastion host of your environment.
If you need Xdebug for PHP please contact our root360 support.
Xdebug Usage
When Xdebug is activated, you can connect to your Xdebug sessions by following these steps:
On your bastion host, start the programm
xdebug-helper
.
This command will start a xdebug proxy in background and print connection information.Run the printed SSH-command in a dedicated terminal
connect your Xdebug client to the debugger
debug-proxy:
localhost:9001
client-listen-port:
the random port printed by the helper-command
IDE-Key:
one of the keys printed by the helper-command
(Every role gets its own IDE-Key to allow full control of the debugging process.)
Simple Example with one role
On Bastion Host
$ 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: <idekey-role1>, <idekey-role2> $
On Client
connect using SSH with specifying client-listen-ports
$ ssh -A -R 20184:localhost:20184 -L 9001:localhost:9001 <bastion-host>
In another set of shells, you can use dbgpClient for debugging each role:
$ curl -LO https://xdebug.org/files/binaries/dbgpClient $ chmod +x dbgpClient # register client with first role $ ./dbgpClient -f -r '<idekey-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.
Now you can start debugging (see Help for commands). When your debugging session is done (exiting the client using Ctrl
+C
), you need to unregister the idekey from the proxy for future usage. Otherwise, it will be blocked.
$ ./dbgpClient -f -u '<idekey-role>' -y localhost:9001
Advanded Example with two roles
On Bastion Host
$ 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 Client
connect using SSH with specifying 2 client-listen-ports (you can choose any port you like, e.g. 20184 and 20185 in this example)
$ ssh -A -R 20184:localhost:20184 -R 20185:localhost:20185 -L 9001:localhost:9001 <bastion-host>
In another set of shells, you can use dbgpClient for debugging each role:
connect to role ‘backend’
$ 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’
# 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.
Now you can start debugging (see Help for commands). When your debugging session is done (exiting the client using Ctrl
+C
), you need to unregister the idekey from the proxy for future usage. Otherwise, it will be blocked.
$ ./dbgpClient -f -u 'xdebug-backend' -y localhost:9001 $ ./dbgpClient -f -u 'xdebug-frontend' -y localhost:9001