Xdebug Cachegrind and MAMP Pro on Mac OSX

Are you running MAMP on OSX? Want to profile your PHP code with Xdebug? It’s easy and here are the steps.

How to run Xdebug on Mac OSX using MAMP

1 Start MAMP

2 Edit php.ini template file through MAMP to enable the extension. Edit the template file via File -> Edit Template -> PHP -> PHP php.ini

edit php.ini template for mamp on mac osx

3 Edit bottom of php.ini template file so that it ends up looking like if you want profile output

xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/tmp"
; DONT REMOVE: MAMP PRO php5.3.6.ini template compatibility version: 1

If you don’t want profile output and just want xdebug running then use

xdebug.profiler_enable = 0
xdebug.profiler_output_dir = "/tmp"
; DONT REMOVE: MAMP PRO php5.3.6.ini template compatibility version: 1

Now when you have errors, if they are sent to standard out, you will see something like this

My php.ini file:

edited php.ini file to run xdebug on mamp mac osx

4 Save edited template and close edit window

5 Restart MAMP

6 Open MAMP’s WebStart page and navigate to PHPInfo tab. Check to make sure that Xdebug is running. Doing a search in the browser window for “Xdebug” makes this easy.
confirm xdebug running on mamp on mac osx

7 If you used the same settings that I have above, when you run PHP code, Xdebug will put the cachegrind.out files in your ‘/tmp’ directory. Open your ‘/temp’ directory and run one of your PHP files to make sure it is working correctly. You can open the ‘/tmp’ directory in finder by opening the terminal and running

open /tmp

cachegrind.out output in /temp folder for mamp on mac osx

8 Now you can use any app that understands those cachegrind.out files to view the profile data. Apps like KCacheGrind (Linux/Windows, KDE), WinCacheGrind (Windows), xdebugtoolkit, and Webgrind.  I went the simple route and used webgrind. Webgrind is a simple web based application that you can run locally on MAMP and it will look for the cachegrind.out files automatically with just one click. Continue for steps on setting up with webgrind.

9 Download Webgrind

10 Setup Webgrind host on MAMP to run Webgrind

Setup webgrind as host on mamp to process xdebug php profile output

11 Visit webgrind url setup on your local MAMP installation. Mine was simply webgrind/

12 If you already have cachegrind output files you should be able to select the file in the “Auto (newest)” dropdown or leave it select at Auto and click update which will reveal the profile data

13 Throw a celebratory fist pump


I think it’s awesome that the MAMP guys have included Xdebug with their release of MAMP 2.01. I wrote this blog post because I wanted to be able to profile some of my projects to find areas where they could be improved. After finally figuring it out it was super simple. The problem was that it took me a long time to set up because of all of the incorrect and outdated information on the internet. I hope this makes it easier for others to get setup. If this post becomes outdated please leave a comment or contact me about what needs to be updated.


I am LOVING Xdebug! Just realized that when you do a var_dump of some variable, Xdebug formats it for you so it’s actually readable! AMAZING!!!!



Things I searched for to find my answers:
php profile
xdebug osx
mamp xdebug
php xdebug osx
cachegrind osx
xdebug mamp
php.ini add extension mamp

Published by


I am a Geek! I hope you enjoyed this recent post.

33 thoughts on “Xdebug Cachegrind and MAMP Pro on Mac OSX”

  1. Thanks Mike for a great tutorial. I have been experiencing all manner of issues trying to set up xdebug, github and other tools with MAMP. Now I think I know why.

    BTW, your tutorial works for MAMP Pro 1.9.5


  2. I was stuck editing a php.ini file I found in “/Applications/MAMP/bin/php/php5.3.6/conf” which isn’t the correct one mind. I didn’t know there was a shortcut to edit the php.ini file within the MAMP app.

    Thank you for posting.

  3. Thanks Mike!
    I finally found I’ve looking for the last few hours! There’re lots of out-dated info on the internet which made me confused more. Now I can go ahead again!!

  4. thanks for this. i’ve also been struggling with outdated information and underwhelming documentation for setting up remote debugging with a commercial grade PHP IDE. It’s been a total time sink. This is the first step by step procedure I’ve found with absolute clarity of how to get the profiler working.

    i’d also appreciate a procedure as effective for setting up remote debugging with Komodo, or Netbeans. any thoughts there?

  5. @Doug Thanks! Glad it helped you out. I don’t use Komodo or Netbeans but would be more than happy to link to a good tutorial on those if anyone shares them with me.

  6. Great post Mike, i’m totally going to get a kick out of profiling my apps. Ever think about doing a follow up post on XDebug talking about some of the features and stats that WebGrind displays? I’d be interested in reading something about.

  7. There’s an issue that came up for me that isn’t addressed in your tutorial. When using regular MAMP you also need to set “display_errors = Off” to “display_errors = On” in the php.ini file. Also you have to make sure “error_reporting = E_ALL” is set and that it’s the only error_reporting line that’s uncommented. Once I did that everything worked like a charm. It took me a couple of hours to figure it out.

    Webgrind looks interesting. I got it working so I’ll be checking that out soon. I’m also trying this super lightweight debugger MacGDBp that might be worth checking out.

    Great tutorial!

  8. Thanks a lot for the Tutorial.
    I wasted a lot of time trying to get it working by editing the ini file directly, and the solution was so easy. :-)

  9. Thank you very much. This was a really handy tutorial.

    I tested it on my latest project immediately. It was great to see that none of my own functions were near the top of the list :)

  10. Thanks for the heads up that mamp comes with xdebug. I didn’t realise it did, so I went to the xdebug site (having previously used the binaries on Windows), realised there was no Mac OS binary and that I’d have to compile it myself, and got an instant headache. Glad I googled before I started ‘make’ing :)

  11. Also you must set html_errors = On on your php.ini template, otherwise the nice green boxes won’t show up

    ; Disable the inclusion of HTML tags in error messages.
    html_errors = On

  12. MAMP doesn’t have a “File” or “Edit Template” option. It seems that it must only be MAMP Pro that has it. You may need to correct the title of your article to refer to the correct product.

  13. Yo! Thanks for the tutorial. I seem to be having a problem.

    I’m running MAMP 2.1.1, and after following your instructions up to step 6, I can’t seem to find xDebug. I do, however, have xCache installed, apparently. Is this supposed to happen?

  14. Tip to all. If you don’t have MAMP pro, you’ll have to find the php.ini manually. To find the correct one, view the output from phpinfo(), and look for “Loaded Configuration File”. This is the php.ini that you need to look at the bottom of and uncomment the xdebug module. Then restart MAMP and you’ll have xdebug!

  15. I run your tutorial to the letter but it does not appear as installed XDebug in phpinfo. Using MAMP Pro latest version. I would like to use XDebug with PhpStorm but I can not.
    Any idea?


Comments are closed.