SugarCRM Developer Blog

Enabling Xdebug under Mac OS X Leopard

25 Nov, 2008
Posted By: John Mertic

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.

As for debugging tools, we’ve used both the tools included in the Eclipse PDT project as well as MacGDBp. For profiling, we use MacCallGrind.

Tags: ,

  • gemmes

    Thank you for this guide, been waiting for a Mac OS X tutorial for xDebug but…

    sudo echo “zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so” >> /etc/apache2/php.ini

    When I get to this line I am getting ‘Permission denied’

    any ideas why?

  • gemmes

    Thank you for this guide, been waiting for a Mac OS X tutorial for xDebug but…

    sudo echo “zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so” >> /etc/apache2/php.ini

    When I get to this line I am getting ‘Permission denied’

    any ideas why?

  • http://sammoffatt.com.au/ pasamio

    The command fails because the echo runs with the root privilege however your shell, which is the thing that actually appends to the file /etc/apache2/php.ini, is still under your local context. Typically its pointless to run “echo” as root because it doesn’t need it.

    You can read about it here: http://www.google.com.au/search?q=sudo+output+redirection

    The generally accepted solution is to run the entire command by getting sudo to call bash and then putting the target command in there with the output redirection, see http://www.dagnall.net/blog/?p=41 for an example.

  • http://sammoffatt.com.au pasamio

    The command fails because the echo runs with the root privilege however your shell, which is the thing that actually appends to the file /etc/apache2/php.ini, is still under your local context. Typically its pointless to run “echo” as root because it doesn’t need it.

    You can read about it here: http://www.google.com.au/search?q=sudo+output+redirection

    The generally accepted solution is to run the entire command by getting sudo to call bash and then putting the target command in there with the output redirection, see http://www.dagnall.net/blog/?p=41 for an example.

  • Kimio

    I did do step by step on your sample. Then I can use Xdebug on eclipse3.4. Thank you. However, breakpoint is not work. I can do step-over and step-in. Why?

  • Kimio

    I did do step by step on your sample. Then I can use Xdebug on eclipse3.4. Thank you. However, breakpoint is not work. I can do step-over and step-in. Why?

  • http://security-wire.com/09/how-to-remove-antivirus-8-rogue-anti-spyware.html remove antivirus 8 virus

    I really appreciate your step by step guide.

Have feedback for us? Drop us a line.
Terms & Conditions | Privacy | Trademark Info | Contact Info | FAQs | SugarCRM Inc.© 2004 - 2009 All rights reserved.