Installing extensions on Mamp Pro for Mac
Placing objects within this box opens a hidden trapdoor...
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.
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:
$ echo "export PATH=/Applications/MAMP/bin/php/php5.6.2/bin:$PATH" >> ~/.profile
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
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.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..
/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
.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
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 /Applications/MAMP/bin/php/php5.6.2/lib/php/extensions/no-debug-non-zts-20131226
. 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
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:
- To get the path variable set up properly
- To find out where I could actually download the php folder I needed to put in my MAMP Pro php include folder
- To figure out how to build the mongo.so file using PCL
- To figure out how to build your own mongo.so file
- To realize that MAMP Pro puts your php.ini file in a different place than all the other tutorials not specific to MAMP Pro tell you to put them
Good luck!