MAMP is an easy to install set of tools for that provides a great local development environment for Mac users (Mac Apache MySQL PHP). OS X does ship with its own built in versions of these tools, but MAMP adds lots of goodies. The newest version of MAMP includes a graphical configuration tool, a choice of PHP versions, web-based tools for administering your databases, and a variety of useful PHP extensions. Unfortunately, MAMP doesn't include everything. If you're developing a site that needs additional PHP extensions like the Memcached library or exotic database drivers, you'll need to use the PEAR and PECL tools to build and install them. PECL (PHP Extension Community Library) and PEAR (PHP Extension and Application Repository) both provide access to a large pool of useful PHP add-ons, but using them with MAMP requires you to do a bit of extra configuration. In this article, you'll learn how to get them running on the latest version of MAMP (2.x).

Installing Components

The usual method for installing PEAR and PECL components is via the command line. Here is an example for installing PHPUnit.
$ pear channel-discover
$ pear install phpunit/PHPUnit
Easy! Unfortunately, if we try this after we've installed MAMP we'll get an error as the "pear" command can't be found and running "php" will point us to OS X's default version.
$ pear
-bash: pear: command not found

$ which php

Let's Fix It

To rectify this we need to add PHP's binaries to our path. The path is an environment variable that denotes which directories to look for commands in. The path can be modified by editing the ".profile" file under your home directory. I've used version 5.3.6 of PHP, but you can choose from whichever versions are available to you.
$ echo "export PATH=/Applications/MAMP/bin/php/php5.3.6/bin:$PATH" >> ~/.profile 
Now you can either restart your terminal session or run the following from your home directory to read in the new path variable.
$ . ./.profile
You should now have the correct binaries on your path and can check this by running the "which" command again.
$ which php

$ which pear

$ which pecl
If this doesn't work make sure that your PHP binaries have execute permissions, an easy way to tell is by running
$ /Applications/MAMP/bin/php/php5.3.6/bin/php -v
-bash: /Applications/MAMP/bin/php/php5.3.6/bin/php: Permission denied

$ chmod +x /Applications/MAMP/bin/php/php5.3.6/bin/*

Try It Out

$ pear channel-discover
Adding Channel "" succeeded
Discovery of channel "" succeeded

$ pear install drush/drush
downloading drush-4.5.0.tgz ...
Starting to download drush-4.5.0.tgz (281,392 bytes)
.........................................................done: 281,392 bytes
install ok: channel://
Hurray! Good times.


For PECL to work we need to prepare the build environment for extensions by making the PHP source available. Download the MAMP Server components and libraries zip file and make yourself a cup of tea whilst you wait. Perhaps have a biscuit as well, I recommend the classic custard cream. You'll also need to have Xcode installed to get Autotools. Once it's downloaded, find the zip file corresponding to your version of PHP, extract it into a new directory in your PHP installation and run the configure script.
$ mkdir /Applications/MAMP/bin/php/php5.3.6/include
$ mv ~/Downloads/MAMP_components_2.0.2/php-5.3.6 /Applications/MAMP/bin/php/php5.3.6/include/php
$ cd /Applications/MAMP/bin/php/php5.3.6/include/php
$ ./configure
All being well, you should now be able to install PECL extensions.
$ pecl install uploadprogress
Build process completed successfully
Installing '/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/'
install ok: channel://
configuration option "php_ini" is not set to php.ini location
You should add "" to php.ini
You can now have some upload progress goodness by editing your php.ini file (in this case /Applications/MAMP/bin/php/php5.3.6/conf/php.ini) and restarting the MAMP servers.

Published in

Sally Young

Sally Young
Senior Technical Architect working across the full-stack and specialising in decoupled architectures. Core JavaScript maintainer for Drupal, as well as leading the JavaScript Modernization Initiative.

Featured Work

Latest Podcasts

Let's Connect

Want to learn more about working with us or just say hello?

Contact Us