ActiveBlog

PHP on Leopard ( or, how to use MAMP instead )
by

, November 13, 2007

I am now running both my work iMac and shiny ( well, matte black actually ) MacBook on Leopard, and for the most part I am really impressed. One thing that has *never* impressed me however was how PHP has been done on OS X. As Wez notes in his recent post about his new PHP / ObjC bridge:

"(note: you'll need to build your own PHP on Leopard, the one Apple ships has had its exports stripped, so you can't run the extension--it'll build, but not run)"

It's not just that you can't load xdebug into Apple's PHP - you can't load *any* external extension, period. So either you're forced to settle for what they ship, you install from MacPorts or from source, or you download MAMP, which is my personal favorite:

http://www.mamp.info/en/download.html

It's simple to set up, it includes everything you'd likely need for web development including APC, and it loads xdebug without complaint. To enable local debugging you should only have to select the MAMP php5 interpreter:

/Applications/MAMP/bin/php5/bin/php

For remote debugging, what you need to do is this:

  1. create the directory '/Applications/MAMP/bin/php5/xdebug/' and copy '/Applications/Komodo IDE 4.2.app/Contents//SharedSupport/php/debugging/5.2/xdebug.so' into that directory.
  2. edit '/Applications/MAMP/conf/php5/php.ini' and add the xdebug configuration options there. Mine look like this:
    ; xdebug config for Linux and Mac OS X
    zend_extension=/Applications/MAMP/bin/php5/xdebug/xdebug.so
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    ;xdebug.remote_host=192.168.69.153
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9010
    xdebug.idekey=jeffg
    xdebug.profiler_enable=1
    xdebug.profiler_output_name=xdebug.cachegrind-out.%s.%p
    
  3. re-start Apache using MAMP's slick controller app and check the phpinfo page; you should see the xdebug configuration block towards the bottom of the page.

The other important thing to do is to make sure the setting for xdebug.remote_port above ( in this case 9010 ) is also configured in Komodo at

Preferences / Debugger / Connection

Set Komodo to listen on 'a specific port' and set this port to the same value as xdebug.remot_port ( again, in my example, port 9010 ).

If you then append XDEBUG_SESSION_START=1 to localhost urls pointing to a php script, you should start a remote debugging session inKomodo and be able to step through the code:

http://localhost/test.php?XDEBUG_SESSION_START=1

Subscribe to ActiveState Blogs by Email

Share this post: