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
Very useful! Worked like a charm!! Thanks!!
Thank you!
Thanx man. 🙂
🙂 glad you find it useful.
Hey,
I had the issue:
fatal error:
‘php.h’ file not found
The following fixed it:
xcode-select –install
Thanks for this man!
Working properly in Mavericks
Hi!
Thanks for the tip!
🙂
amazing guide, thanks man!
Thank you SO MUCH for your clear and accurate instructions! There is far too much random/half-baked blather on the Internet posing as solutions to technical questions/problems. In contrast, you are an A-list contributor, everything just works now and it’s clear -why- it works.
Very useful article!. But it can be done in a slimpleer way. You can install autoconf with brew and then install php-mongo-driver using pecl.
http://stackoverflow.com/questions/9322742/php-autoconf-errors-on-mac-os-x-10-7-3-when-trying-to-install-pecl-extensions
Thanks!
Greatly appreciated, Andres!
not work:
asd:autoconf low$ sudo curl http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz > autoconf.tar.gz
-bash: autoconf.tar.gz: Permission denied
Hi Andres, I follow your fantastic tutorial and I can’t have any error during all process. At the and the process I close and reload also MAMP but in phpinfo I can’t see MONGO info…..why? where I wrong?
thank you