Enabling Xdebug under Mac OS X Leopard

bsoremsugar —  November 25, 2008 — 7 Comments

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.

7 responses to Enabling Xdebug under Mac OS X Leopard

  1. 

    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?

  2. 

    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?

  3. 

    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.

  4. 

    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.

  5. 

    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?

  6. 

    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?

  7. 

    I really appreciate your step by step guide.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s