• Home
  • My Work
  • Installing PECL Mongo Driver for MAMP on Mac OS 10.8
https://torbjornzetterlund.com/wp-content/uploads/2014/10/mongoDB-e1413038870221-960x600_c.jpg

Installing PECL Mongo Driver for MAMP on Mac OS 10.8


Get Xcode

Get the latest Xcode from the Apple app store, free download version, then install and launch it.

Next you need to install the Xcode command line tools, easiest way to do so by running in the Terminal:

xcode-select --install

Next you need to set the path 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.5.10 of MAMP, but you can choose from whichever versions are available to you.

$ echo “export PATH=/Applications/MAMP/bin/php/php5.5.10/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 pecl
/Applications/MAMP/bin/php/php5.5.10/bin/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.5.10/bin/php -v
-bash: /Applications/MAMP/bin/php/php5.5.10/bin/php: Permission denied

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

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.

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.5.10/include
$ mv ~/Downloads/php-5.5.10 /Applications/MAMP/bin/php/php5.5.10/include/php
$ cd /Applications/MAMP/bin/php/php5.5.10/include/php
$ ./configure

All being well, you should now be able to install PECL mongo extensions.

sudo pecl install mongo

A few moments later, you should have the mongo driver installed. Now all you need to do is tell PHP to load the extension.

To do this, edit /etc/php.ini:

$ sudo vi /Applications/MAMP/bin/php/php5.5.10/conf/php.ini

(Feel free to use whatever editor you want. I tend to use vi.)

At the bottom of the php.ini file, simply add this line:

extension=mongo.so

Save the file, and the extension should be loaded with each invocation of PHP.

Now from the command line you should be able to verify that the extension is being loaded:

$ php --re mongo

The command above should dump information about the public API for the mongo driver. This API is well-documented and the docs can be accessed online at PHP.net.

Make sure you restart your MAMP to pick up the new Mongo driver!

Menu