简体   繁体   中英

Installing Mongo Driver on MAMP

I have downloaded, compiled and installed the latest mongo driver for php & it's been placed at:

 /opt/local/lib/php/extensions/no-debug-non-zts-20090626/mongo.so

How would I go about adding this to the MAMP php.ini file? I have looked at just trying to add the "extention=mongo.so" however this does not work. I also tried to place the mongo.so file inside the dir:

/Applications/MAMP/bin/php/php5.4.4/lib/php/extensions/no-debug-xxx/

And added the correct line of code to php.ini...

Would I have to tell it the directory the extension is in?

To install latest Mongo driver on MAMP

1 - install autoconf using homebrew or Mac Ports

brew install autoconf

2 - Download php 5.4.10 source from php.net .

3 - rename uncompressed php source folder from php-5.4.10 to php and paste it in this folder

/Applications/MAMP/bin/php/php5.4.10/include/

4- using the terminal open php folder and run ./configure

cd /Applications/MAMP/bin/php/php5.4.10/include/php/ && ./configure

5 - Add MAMP bin to your ~/.bash_profile

echo "export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH" >> ~/.bash_profile source ~/.bash_profile

6 - install latest mongo

pecl install mongo

7- restart MAMP server :).

8- Enable the extension Edit /Applications/MAMP/bin/php/php5.4.10/conf/php.ini Add the following line after the section named "; Extensions":

extension=mongo.so

Before you go off trying to install mongo, you really should install MAMPs special tools for adding extensions and follow this tutorial for getting set up:

http://blog.jellystyle.com/post/37099202581/installing-php-extensions-with-mamp

This allows you to use the correct pecl, the correct pear, and will install mongo.so in the correct location for MAMP to use it.

Then, from there just run sudo pecl install mongo and restart the MAMP service.

Then.... edit the php.ini file:

  1. Find the Extensions section via search (in vim you can just type /Extensions and hit enter
  2. under the Extensions section add this line if it isn't already there: extension=mongo.so
  3. make sure the path to mongo.so is something like this: /Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/mongo.so

Write a short PHP script which contains the line <?php phpinfo(); ?> <?php phpinfo(); ?> . Run it. Search for extension_dir to figure out the directory where extensions are supposed to be loaded from.

If you want to use PHP CLI, run php -i | grep extension_dir php -i | grep extension_dir as well. Both should point to the same directory. Place your mongo.so there.

Next, have a look at Loaded Configuration File . This is the php.ini used for Apache or CLI (these files usually are different). Add extension=mongo.so in the proper one (or in both).

Restart Apache (done via sudo service apache2 restart on Unix) and check phpinfo() output again. MongoDB should show up as loaded extension.

I think one of the problems i was having was trying to use MAMP which was confusing me. After much failure I just decided to use PHP as it is and it worked correctly. There was a good guide to any setup instructions here: http://www.phpied.com/installing-php-and-apache-on-mac-osx-that-was-pretty-easy/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM