Xdebug for remote server not connecting

For me, xdebug.remote_connect_back = On does not work. What I did was to set ssh port forwarding on my client machine.

xdebug config on the remote machine:

xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_handler = dbgp
xdebug.remote_mode = req

forward ports on the client machine:

ssh -g -N -lusername -R9000:127.0.0.1:9000 [remote.host.ip]

The shell access on the remote machine must be allowed.


The server running PHP (and XDebug) needs to be able to connect to your workstation/desktop.

Diagram

So you'll need the server set up accordingly by either telling it to connect to a specific IP-address (xdebug.remote_host) or to automatically "connect back" (xdebug.remote_connect_back). The latter has some security implications, though. These are outlined in the manual.


The key directive is this:

xdebug.remote_connect_back = On

This allows the web server to connect to whatever computer is asking for a debugging session. This way you don't have to hard-code an IP address and are able to share Xdebug. This directive was not present in earlier versions and is often omitted from tutorials and documentation.

You also need to verify that every client computer accepts incoming connections to port 9000 (xdebug.remote_port). This includes configuring the firewall and making sure the debugger client is up and running


Xdebug 3 upgrade guide for remote debugging

Summary of: https://xdebug.org/docs/upgrade_guide

Required PHP configuration changes/additions:

  • remove xdebug.(remote_enable|default_enable|profiler_enable|auto_trace|coverage_enable)
  • add xdebug.mode=debug OR use develop|coverage|gcstats|profile
  • add xdebug.start_with_request=yes
  • xdebug.remote_autostart is replaced by xdebug.mode=debug with xdebug.start_with_request=yes
  • xdebug.remote_host is replaced by xdebug.client_host
  • xdebug.remote_port is replaced by xdebug.client_port OR use new default in IDE setting (more below)

Example new configuration

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.idekey=myKey
xdebug.client_host=x.y.z.a
xdebug.remote_handler=dbgp

Where

  • x.y.z.a = your IDE host
  • myKey = your configured key in the IDE

Required IDE configuration changes/additions:

  • set remote_port to 9003 (xdebug's new default port) OR set xdebug.client_port to 9000 in the configuration above to keep the old default