Xdebug Debugging On A Remote Server

I have started to use virtual machines to develop sites rather than installing a local web server. This allows me to replicate the exact setup of the server I will be deploying to with ease. For each virtual machine I set up a shared folder which allows me to store the files locally whilst being able to run the code on the virtual machine. One thing I missed was the ability to use xdebug to debug the sites through Netbeans, so I set about trying to set up the virtual hosts to allow me to use xdebug remotely.

All that is needed was to add a xdebug.remote_connect_back clause to the xdebug.ini file found in the PHP configuration. Set this value to 1 to automatically connect back to any xdebug session that is created on the server.

xdebug.remote_connect_back = 1

Remember that you will also need to setup the correct hosts directive on your system to allow your web browser to open up and accept the xdebug session. Additionally, because I was using virtual machines I could never be sure that the IP address of the host computer was going to be the same. For this reason the xdebug.remote_host clause should be removed so that xdebug was IP address agnostic. I sill needed to tweak my hosts file every now and then, but I wouldn't need to edit the xdebug.ini file and restart Apache.

I should note here that if you are doing this on a server the removal of the xdebug.remote_host clause will mean that anyone will be able to create an xdebug session on the server. Which is a bit of a security problem.

Here is the xdebug configuration on my virtual servers in full. The first clause (for the xdebug binary) might be different on your setup.

zend_extension=/usr/lib/php5/20100525/xdebug.so

xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.remote_connect_back = 1

If you have a development server then you should remember that xdebug will only be able to create one debugging session at a time.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
7 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.