Installing the Latest XDebug on OSX

Installing or updating XDebug is not that difficult. The title indicates it's for OSX, but this should work pretty much the same on any Linux system running apache.

The first thing to do is backup your existing 'xdebug.so' file if you have it installed already. If this ends up not working out for some reason, you can always copy it back. If you're unsure where it is installed, search your php.ini file for "xdebug". The absolute path to the file should be defined in the 'zend_extension' setting.

Let's create a directory to work in and clone the project:

$ mkdir ~/work
$ cd ~/work
$ git clone https://github.com/xdebug/xdebug.git
$ cd xdebug

Configure and build xdebug:

$ phpize
$ ./configure --enable-xdebug
$ make

You can keep 'xdebug.so' file anywhere, but I prefer to keep it with the other modules in the php 'extension_dir'. If you are unsure where this is, you can view the output of phpinfo(); and search for 'extension_dir'. Mine is: /usr/lib/php/extensions/no-debug-non-zts-20090626/

$ sudo cp modules/xdebug.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

If you haven't installed xdebug before, then you will need to add it to your php.ini file. I'll add some basic settings as well so all I need to do is setup my IDE to listen on port 9000. When PHP is executed, it will look for something listening at localhost:9000, and if it doesn't detect any listener, it will run as if debugging was off.

; adding to php.ini
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1

Now, all that's left is to restart apache.

$ sudo apachectl restart