I spent way too many hours last night (this morning? What time is it?) trying to install MongoDB for a site I was building which requires it, and most of the documentation I read (which was super helpful) didn't quite fix my issues. I'm no systems administrator, so it took a lot of time to stumble through this issue. The solution I finally came to was a conglomeration of a few tutorials I read online, so I'm posting it here in hopes it will help someone else.
If you go into terminal and run
which php
, chances are you'll get something like
usr/bin/php/
This means that php is set to run from Apple's pre-installed instance of PHP, not MAMP's, so any modules you install will not take effect within MAMP, unless you add MAMP's php binaries to your path variable:
You'll need to figure out what version of PHP you're running in MAMP and change the path above accordingly. Within MAMP Pro, if you're using virtual hosts, just go to the Hosts tab and find your site, and note the version of PHP listed there. And just for safe measure, you might want to just go into finder, within your MAMP/bin/php directory, and find that folder. If you drag the folder straight in to terminal, you'll get the absolute path that you need to copy to the echo statement above.
Once you run this command, you should read in the new path variable with this command:
. ./.profile
Now, if you run
which php
, rather than
usr/bin/php
you should see the folder you just specified in the path variable:
/Applications/MAMP/bin/php/php5.6.2/bin/php
. If you get something about the command which not being found, just restart terminal and try again. I had some weirdness happen around that.
You might also just want to see what's in your /.profile file, by running
sudo vim /.profile
- I've configured a lot of sites on my machine based on instructions from backend devs that I barely understood, so mine had some duplicates and unused path settings which I cleaned up.
Now that you're pointing to the right version of PHP within MAMP, you need to install the tools that will allow you to build your extension (extensions can't just be downloaded, they have to be compiled within your environment to ensure they have the proper headers). I saw a lot of tutorials referencing a certain set of downloadable tools available from MAMP's download page, but these were written around the time of MAMP 2. As far as I can tell, those are no longer available as of MAMP 3. I was actually able to download them straight from php, here..
Once they are downloaded, go to that folder within MAMP where your version of PHP is running (
/Applications/MAMP/bin/php/php5.6.2/bin/php
) and make a directory called
include
. Extract the file you just downloaded - it should leave you with a folder called php-5.6.2 (or whatever version you downloaded). Copy that into the include folder you just made, and rename it to
php
.
Now you can install extensions from this folder. Is your path still pointing to the right place? Run
which php
to find out. For some reason, I found that if I screwed up in the install process, this would revert back to
usr/bin/php
so if you have issues, always check that along the way. You'll now need the mongodb extension itself. You should be able to run:
sudo pecl install mongo
ONLY IF YOU HAVE ISSUES
If for some reason it doesn't work for you, read below. Otherwise, skip ahead to the next. If it didn't work, you can download Mongo directly from here and, unzip it somewhere on your computer (the desktop is fine). Open up another terminal window and cd into that directory, then run the following commands:
phpize
./configure
make
sudo make install
This will create a
mongo.so
file within the
modules
folder of the mongo folder you just downloaded. Take that mongo.so file, and copy it into the appropriate MAMP folder. For me, that folder would be
. If you open that up in finder, you should see a bunch of other .so files. Copy mongo.so into there. You can verify the proper path by opening up the php.ini file (
/Applications/MAMP/bin/php/php5.6.2/conf
), and searching for the extensions directory listed there.
IF YOU STILL HAVE ISSUES
Now, assuming you've got your mongo.so built properly and copied into the right folder, here's what tripped me up. You need to add the extension to the list of installed extensions within php.ini. However, MAMP Pro does not put these in the folder. To find out where it's putting them, you could put a php file with the contents:
phpinfo()
PHP Version 5.5.9-1ubuntu4.29
System
Linux extra 3.13.0-57-generic #95-Ubuntu SMP Fri Jun 19 09:28:15 UTC 2015 x86_64
This program makes use of the Zend Scripting Language Engine: Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.
Phar based on pear/PHP_Archive, original concept by Davey Shafik. Phar fully realized by Gregory Beaver and Marcus Boerger. Portions of tar implementation Copyright (c) 2003-2009 Tim Kientzle.
Edin Kadribasic, Marcus Boerger, Johannes Schlueter, Moriyoshi Koizumi, Xinchen Hui
Continuity
Alex Leigh (based on nsapi code)
Embed
Edin Kadribasic
FastCGI Process Manager
Andrei Nigmatulin, dreamcat4, Antony Dovgal, Jerome Loyet
ISAPI
Andi Gutmans, Zeev Suraski
litespeed
George Wang
NSAPI
Jayakumar Muthukumarasamy, Uwe Schindler
phttpd
Thies C. Arntzen
pi3web
Holger Zimmermann
Sendmail Milter
Harald Radi
thttpd
Sascha Schumann
tux
Sascha Schumann
WebJames
Alex Waugh
Module Authors
Module
Authors
BC Math
Andi Gutmans
Bzip2
Sterling Hughes
Calendar
Shane Caraveo, Colin Viebrock, Hartmut Holzgraefe, Wez Furlong
COM and .Net
Wez Furlong
ctype
Hartmut Holzgraefe
cURL
Sterling Hughes
Date/Time Support
Derick Rethans
DB-LIB (MS SQL, Sybase)
Wez Furlong, Frank M. Kromann
DBA
Sascha Schumann, Marcus Boerger
DOM
Christian Stocker, Rob Richards, Marcus Boerger
enchant
Pierre-Alain Joye, Ilia Alshanetsky
ereg
Rasmus Lerdorf, Jim Winstead, Jaakko Hyvätti
EXIF
Rasmus Lerdorf, Marcus Boerger
fileinfo
Ilia Alshanetsky, Pierre Alain Joye, Scott MacVicar, Derick Rethans
Firebird/InterBase driver for PDO
Ard Biesheuvel
FTP
Stefan Esser, Andrew Skalski
GD imaging
Rasmus Lerdorf, Stig Bakken, Jim Winstead, Jouni Ahto, Ilia Alshanetsky, Pierre-Alain Joye, Marcus Boerger
GetText
Alex Plotnick
GNU GMP support
Stanislav Malyshev
Iconv
Rui Hirokawa, Stig Bakken, Moriyoshi Koizumi
IMAP
Rex Logan, Mark Musone, Brian Wang, Kaj-Michael Lang, Antoni Pamies Olive, Rasmus Lerdorf, Andrew Skalski, Chuck Hagenbuch, Daniel R Kalowsky
Input Filter
Rasmus Lerdorf, Derick Rethans, Pierre-Alain Joye, Ilia Alshanetsky
InterBase
Jouni Ahto, Andrew Avdeev, Ard Biesheuvel
Internationalization
Ed Batutis, Vladimir Iordanov, Dmitry Lakhtyuk, Stanislav Malyshev, Vadim Savchuk, Kirti Velankar
JSON
Omar Kilani, Scott MacVicar
LDAP
Amitay Isaacs, Eric Warnke, Rasmus Lerdorf, Gerrit Thomson, Stig Venaas
LIBXML
Christian Stocker, Rob Richards, Marcus Boerger, Wez Furlong, Shane Caraveo
mcrypt
Sascha Schumann, Derick Rethans
MS SQL
Frank M. Kromann
Multibyte String Functions
Tsukada Takuya, Rui Hirokawa
MySQL driver for PDO
George Schlossnagle, Wez Furlong, Ilia Alshanetsky, Johannes Schlueter
MySQL
Zeev Suraski, Zak Greant, Georg Richter, Andrey Hristov
MySQLi
Zak Greant, Georg Richter, Andrey Hristov, Ulf Wendel
MySQLnd
Andrey Hristov, Ulf Wendel, Georg Richter, Johannes Schlüter
OCI8
Stig Bakken, Thies C. Arntzen, Andy Sautins, David Benson, Maxim Maletsky, Harald Radi, Antony Dovgal, Andi Gutmans, Wez Furlong, Christopher Jones, Oracle Corporation
ODBC driver for PDO
Wez Furlong
ODBC
Stig Bakken, Andreas Karajannis, Frank M. Kromann, Daniel R. Kalowsky
OpenSSL
Stig Venaas, Wez Furlong, Sascha Kettler, Scott MacVicar
Oracle (OCI) driver for PDO
Wez Furlong
pcntl
Jason Greene, Arnaud Le Blanc
Perl Compatible Regexps
Andrei Zmievski
PHP Archive
Gregory Beaver, Marcus Boerger
PHP Data Objects
Wez Furlong, Marcus Boerger, Sterling Hughes, George Schlossnagle, Ilia Alshanetsky
PHP hash
Sara Golemon, Rasmus Lerdorf, Stefan Esser, Michael Wallner, Scott MacVicar
Posix
Kristian Koehntopp
PostgreSQL driver for PDO
Edin Kadribasic, Ilia Alshanetsky
PostgreSQL
Jouni Ahto, Zeev Suraski, Yasuo Ohgaki, Chris Kings-Lynne
Pspell
Vlad Krupin
Readline
Thies C. Arntzen
Recode
Kristian Koehntopp
Reflection
Marcus Boerger, Timm Friebe, George Schlossnagle, Andrei Zmievski, Johannes Schlueter
Sessions
Sascha Schumann, Andrei Zmievski
Shared Memory Operations
Slava Poliakov, Ilia Alshanetsky
SimpleXML
Sterling Hughes, Marcus Boerger, Rob Richards
SNMP
Rasmus Lerdorf, Harrie Hazewinkel, Mike Jackson, Steven Lawrance, Johann Hanne, Boris Lytochkin
SOAP
Brad Lafountain, Shane Caraveo, Dmitry Stogov
Sockets
Chris Vandomelen, Sterling Hughes, Daniel Beulshausen, Jason Greene
SPL
Marcus Boerger, Etienne Kneuss
SQLite 3.x driver for PDO
Wez Furlong
SQLite3
Scott MacVicar, Ilia Alshanetsky, Brad Dewar
Sybase-CT
Zeev Suraski, Tom May, Timm Friebe
System V Message based IPC
Wez Furlong
System V Semaphores
Tom May
System V Shared Memory
Christian Cartus
tidy
John Coggeshall, Ilia Alshanetsky
tokenizer
Andrei Zmievski, Johannes Schlueter
WDDX
Andrei Zmievski
XML
Stig Bakken, Thies C. Arntzen, Sterling Hughes
XMLReader
Rob Richards
xmlrpc
Dan Libby
XMLWriter
Rob Richards, Pierre-Alain Joye
XSL
Christian Stocker, Rob Richards
Zip
Pierre-Alain Joye
Zlib
Rasmus Lerdorf, Stefan Roehrich, Zeev Suraski, Jade Nicoletti, Michael Wallner
PHP Documentation
Authors
Mehdi Achour, Friedhelm Betz, Antony Dovgal, Nuno Lopes, Hannes Magnusson, Georg Richter, Damien Seguy, Jakub Vrana
Editor
Philip Olson
User Note Maintainers
Daniel P. Brown, Thiago Henrique Pojda
Other Contributors
Previously active authors, editors and other contributors are listed in the manual.
PHP Quality Assurance Team
Ilia Alshanetsky, Joerg Behrens, Antony Dovgal, Stefan Esser, Moriyoshi Koizumi, Magnus Maatta, Sebastian Nohn, Derick Rethans, Melvyn Sopacua, Jani Taskinen, Pierre-Alain Joye, Dmitry Stogov, Felipe Pena, David Soria Parra
Websites and Infrastructure team
PHP Websites Team
Rasmus Lerdorf, Hannes Magnusson, Philip Olson, Lukas Kahwe Smith, Pierre-Alain Joye, Kalle Sommer Nielsen
Event Maintainers
Damien Seguy, Daniel P. Brown
Network Infrastructure
Daniel P. Brown
Windows Infrastructure
Alex Schoenmaker
PHP License
This program is free software; you can redistribute it and/or modify it under the terms of the PHP License as published by the PHP Group and included in the distribution in the file: LICENSE
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If you did not receive a copy of the PHP license, or have any questions about PHP licensing, please contact license@php.net.
into a visible location in your application, and read out the path listed in the "Loaded Configuration File" section. Or you can just go into the MAMP Pro application and choose
File > Edit Template > PHP > PHP 5.6.2 php.ini
, which will open up that location directly for editing. Find the list of extensions there, and add:
extension=mongo.so
Now restart MAMP, and mongo should be installed.
If you are having troubles, here were the posts I found most helpful: