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/92f3795d2dcd5e74fb6f47a30b4f6293ee31fada/Library/Formula/xhprof.rb 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

Toon Ketels on Wed, 12/09/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.

Gajus Kuizinas on Mon, 15/10/2012 - 21:34

I am the developer of the http://xhprof.io/. It is meant to become a successor of the present XHProf UI. It isn't a production ready software, though everyone is welcome to contribute.

swentel on Mon, 15/10/2012 - 22:56

Wow, that is indeed nice, I'll keep an eye on it!

Gajus on Sun, 02/12/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.

Tanc on Tue, 15/01/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

Akselsen on Tue, 12/02/2013 - 11:08

Thanks for these instructions. Also thanks to Tancs comment for the setting of the paths

swentel on Tue, 12/03/2013 - 15:45

Oh lord, that's so sweet - added at the top of the article.

Add reply

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Have you written a response to this? Let me know the URL by sending a webmention.