Xdebug is the most popular debugging and profiling tool available for PHP, and one we use here internally quite a bit during the development process. Available as an extension for PHP, it is easily installed on PHP for Windows by dropping in the the correct dll into the PHP extensions directory and adding it to the php.ini file, or on most Unix systems by using the pecl install xdebug command. For those setups, the instuctions on the Xdebug website will get you up and running in no time.
However, if you wish to get Xdebug running on the PHP installation included with Mac OS X Leopard, the pecl install xdebug command won’t work. The problem was earlier illustrated on this developer’s blog post, where the command line PHP version is built for 32-bit, while the Apache module is 64-bit. So for this we’ll need to build the extension as a 64-bit extension and create a seperate php.ini file just for Apache to use. Here’s how we do that:
- Download xdebug from http://xdebug.org, and unzip it.
- cd to the xdebug-x.y.z directory in the archive, then run the following commands to build the extension
$ phpize $ MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure --enable-xdebug $ make $ sudo make install
- Now we need to copy our original php.ini to one we’ll use exclusively for Apache.
$ sudo cp /etc/php.ini /etc/apache2/php.ini $ sudo echo "zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so" >> /etc/apache2/php.ini $ sudo echo "PHPIniDir /etc/apache2" >> /etc/apache2/other/php5.conf $ sudo apachectl restart
You should now be up and running; you can confirm by checking the output of phpinfo(); in the browser.