February 12, 2009

Getting xDebug Working on Mac OS X with MacPorts

Kevin Hallmark @ 3:25 pm —

xdebug is a powerful PHP debugging tool. With xdebug you can get all sorts of debugging out, stack traces, and memory usage (as well as delta). It also gives you classic code-stepping tools and breakpoint. Finally, you can debug your PHP applications! Getting it working on Mac OS X has been a bit confusing, but this how to guide will give you all the tools you need!

Before we proceed, you have MacPorts installed right?

So how do we go about getting xdebug? First, install xdebug:

sudo port install php5-xdebug

Next enable xdebug. All this goes in your php.ini

; NOTE: This line adds the xdebug extension. The macports install will give you the path, 
; or may even add this automatically. Be smart, look for a similar line in your config first.
; (Edit: 06/22/2012)
zend_extension="/opt/local/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

; General config
;Dumps local variables on exception
xdebug.show_local_vars=On
;Dump server variables
xdebug.dump.SERVER=*
;Dump global variables
xdebug.dump_globals=On
xdebug.collect_params=4;

; Tracing
xdebug.auto_trace=On
xdebug.trace_output_dir= /opt/local/php_traces/
xdebug.show_mem_delta=On
xdebug.collect_return=On

; Profiler
xdebug.profiler_enable=1
xdebug.profiler_output_dir=/opt/local/php_traces

; Debugging. You might need to specify your host with some additional options
xdebug.remote_enable=1

For viewing profile output:
http://www.maccallgrind.com/

You will use this program to open the cachegrind.out files in /opt/local/php_trace

For using the debugger:
http://www.bluestatic.org/software/macgdbp/

Just put “XDEBUG_SESSION_START=session_name” in your query string. Session_name can be any alphanumeric string.

You can set a breakpoint with: xdebug_break()

6 Responses to “Getting xDebug Working on Mac OS X with MacPorts”

  1. Thoughts & Ideas About Web Development» Blog Archive » Before You Implement Caching On Your Website Says:

    […] Kevin Hallmark’s instructions Getting xDebug Working on Mac OS X with MacPorts […]

  2. Tweets that mention Getting xDebug Working on Mac OS X with MacPorts « little black hat – The online home of Kevin Hallmark -- Topsy.com Says:

    […] This post was mentioned on Twitter by Kevin Hallmark. Kevin Hallmark said: My first "macports xdebug" article is back in the top results on Google after falling off. Yay! #shamelessplug http://tinyurl.com/yauyblt […]

  3. Michael Cannon Says:

    Thanks for the tip on getting going with xdebug on OSX.

    These days, the Zend extension path is `zend_extension=”/opt/local/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so”`

  4. Kevin Hallmark Says:

    Thanks! I’m updating the original post.

  5. Install and activate xdebug in MacPorts | Programming and Technology Says:

    […] Ref: http://www.littleblackhat.com/blog/2009/02/getting-xdebug-working-on-mac-os-x-with-macports/ […]

  6. Ulrik Street-Poulsen Says:

    Thanks for the instructions.

    Quick word of warning though, having xdebug.collect_params=4 can cause big memory problems in some cases. The default is 0. See http://xdebug.org/docs/all_settings for more info on settings.

Leave a Reply

Logged in as . (Logout)