Quick Tip – Enabling XDebug in MAMP for OSX

I’ve swapped over to MAMP for my local web development needs on OSX. I work with a variety of projects that require different versions of PHP, and MAMP allows me to change the PHP version quickly and easily. It also comes with a preconfigured MySQL instance for my database needs.

By default, XDebug is not enabled in MAMP. I found plenty of MAMP Pro posts on how to setup XDebug, but not for simple MAMP. Here’s what you need to do.

Really the only trick to know is that MAMP keeps two configuration files for each PHP version. One serves as a template when you start up PHP. There are two files you need to edit:

/Applications/MAMP/conf/php[version]/php.ini

/Applications/MAMP/bin/php/php[version]/conf/php.ini

In both of these files, go down to the very bottom of the config file, where the [xdebug] section is, and uncomment ( remove the ; ) zend_extension line. In addition, add the following lines:

xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp

The final result will look something like this:

[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.4.34/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp

Restart MAMP (or launch it if you haven’t done so yet) and XDebug should be all set for whatever environment you use!

Hope this helps!

One thought on “Quick Tip – Enabling XDebug in MAMP for OSX

  1. I’ve had to solve this two years ago to set up PHP debugging with MAMP, but forgot what the snatch was. I just spent three frustrating hours trying to compile xdebug (http://xdebug.org/wizard.php) only to stumble upon an ever-widening forest of errors and missing source files.

    And then I came across this page and of course! I need to change BOTH the php.ini files … thanks, you saved my day!

What are your 10 bits on the matter? I want to know!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s