avatar

Andres Jaimes

Installing the PHP/MongoDB extension on Mac OSX 10.8

By Andres Jaimes

Installing PHP/MongoDB extension is a two steps task on OSX:

  • Install the autoconf tool required for compiling the extension
  • Install the Mongo extension

You have to install autoconf in order to avoid the following error:

Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize’ failed

Enough talk, hands on work…

 

Step 1. Install the autoconf tool

Download the latest source version:

cd
mkdir autoconf
cd autoconf
curl http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz > autoconf.tar.gz

Untar it

tar -xvzf autoconf.tar.gz

Configure and make

cd autoconf-2.69
./configure
make
sudo make install
export PHP_AUTOCONF=/usr/local/bin/autoconf

autoconf is installed on /usr/local/bin/autoconf by default.

 

Step 2. Install the Mongo extension

Download the driver from the official repository:

cd
mkdir mongo-php-driver
cd mongo-php-driver
curl https://codeload.github.com/mongodb/mongo-php-driver/zip/master > mongo-php-driver-master.zip

Unzip it

unzip mongo-php-driver-master.zip
cd mongo-php-driver-master

Configure and build

phpize
./configure
make all
sudo make install

Check that the extension was successfully created:

ls /usr/lib/php/extensions/no-debug-non-zts-20090626/

You should see the mongo.so extension file in there.

Make sure the previous directory is the same as the PHP extension directory by running:

php -i | grep extension_dir
  extension_dir => /usr/lib/php/extensions/no-debug-non-zts-20090626 =>
                   /usr/lib/php/extensions/no-debug-non-zts-20090626

If it’s not, change the extension_dir in php.ini or move mongo.so. (See below if you don’t have a php.ini file)

To load the extension on PHP startup, add the following line to your php.ini file:

extension=mongo.so

If you don’t have a php.ini file you have to copy it from your php.ini.default file like this:

sudo cp /private/etc/php.ini.default /private/etc/php.ini
sudo nano /private/etc/php.ini

Add the previous “extension” line to your file, save it and restart apache

sudo apachectl restart

Enjoy