Installing XHProf on a Mac with Homebrew

Update 12/3/2013: the absolute easiest way is simply https://github.com/cam8001/php-xhprof-mamp

There are several ways to install XHProf on your mac in a MAMP environment. After a lot fails, the easiest way in my opinion is using Homebrew. The rest of the article assumes you already have this installed, so let's get to the XHProf install.

  1. Download the XHProf Homebrew Formula from https://github.com/msonnabaum/homebrew/blob/92f3795d2dcd5e74fb6f47a30b4f... and copy this file to /usr/local/Library/Formula/
  2. Fire 'brew install autoconf' to make sure autoconf is installed.
  3. Fire 'brew install xhprof' on the command line. You might get an error downloading the pcre package (depending on your homebrew version):
    Error: Failure while executing: /usr/bin/curl -f#LA Homebrew\ 0.8\ (Ruby\ 1.8.7-249;\ Mac\ OS\ X\ 10.7.3) ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.bz2 -o /Users/swentel/Library/Caches/Homebrew/pcre-8.12.tar.bz2
    In that case, go to https://github.com/mxcl/homebrew/blob/master/Library/Formula/pcre.rb and download that file into /usr/local/Library/Formula/ and run the command again from shell.
  4. The extension is now built and can be copied to your MAMP installation:
    cp /usr/local/Cellar/xhprof/0.9.2/xhprof.so /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/ 
  5. Go to your php.ini file in your MAMP installation and paste following code and restart MAMP.
    [xhprof]
    extension=xhprof.so
    ;This is the directory that XHProf stores it's profile runs in.
    xhprof.output_dir=/tmp
That's it. Should take you about 5 minutes. Took me a couple of wasted hours, but it's worth doing. And now you can finally toggle the XHProf option on the devel settings page in case you're working with Drupal.

Other resources about installing XHprof:

Comments

Submitted by Toon Ketels on September 12, 2012 - 19:36

If you want to use xhprof with devel module, make sure to set the directory to /usr/local/Cellar/xhprof/0.9.2 in devel config page.

Submitted by Gajus on December 2, 2012 - 03:25

Thank you. It has progressed a lot since the first time I have posted this. It is still in pre-release state, though might just be the right time to go ahead with the first official release.

Submitted by Tanc on January 15, 2013 - 09:31

To get phpize to work I also had to:
export PHP_AUTOCONF=/usr/local/bin/autoconf
export PHP_AUTOHEADER=/usr/local/bin/autoheader

You are here