Monthly Archives: June 2011

How to use Xdebug from behind a NAT

I don’t work with PHP any more, except when I have to maintain a huge code-base that runs only on a specific version of PHP, on a specific version of a specific Linux distro and from a specific directory using a specific… you get the picture.

I run this thing in a virtual machine and connect to it trough a VPN, so the only method to debug was print and error_log.

For a year I kept trying to connect Xdebug back to Netbeans (yes, in PHP the debugger connects to the IDE) and for a year I kept ignoring the obvious: ssh.

The beauty of this is in its simplicity: just go into your php.ini and set Xdebug to connect to localhost.

I assume the rest of the configuration is using defaults, like port 9000 and stuff.

Now, set up a reverse ssh tunnel to the server with port 9000 on both ends. Something like:
ssh -R 9000:localhost:9000 user@server. You can do this with Putty too.

You should now be able to debug the hell out of that code running on your specific… ok I’ll stop now.