I use netbeans as my php IDE and having a debugger is incredibly helpful when building large webapps.
When Xdebug works, it’s an incredibly useful tool as one can step through code, keeping an eye on variables at any point. It is very flaky though and while my xdebug virtual machine was working perfectly yesterday, today xdebug simply won’t connect to Netbeans so I am reinstalling and documenting the process this time.

I’ve started with a standard LAMP virtual machine – I did a quick, automated Ubuntu 12.04 server install in VMWare fusion, then added apache, php5, mysql, phpmyadmin, debug and openssh-server.
My web app makes heavy use of Apache’s mod-rewrite engine. To enable this, we need to both enable the engine (sudo a2enmod rewrite) and also change the virtual host (/etc/apache/sites-available/00-default) to read “allowOverride all” instead of “allowOverride none”.

Phpmyadmin also has a habit of not fully installing, so I added “Include /etc/phpmyadmin/apache.conf” to the end of my /etc/apache2/apache2.conf.

To enable xdebug, I add the following lines to my /etc/php5/apache2/php.ini:
zend_extension=/usr/lib/php5/<date+lfs>/xdebug.so
xdebug.remote_enable=on</date+lfs>

There are also a number of configuration options one can add. The main one for me is:
xdebug.remote_host=hostname
where hostname is the hostname of my laptop on which I run Netbeans. This is because Xdebug initiates the connection to the IDE. If I was running the IDE and Xdebug on the same machine, I could of course have left this out as the default is localhost.

That’s it!