Install and run MongoDB
It is possible to install and use MongoDB along with MAMP PRO PHP. Installing and running MongoDB takes several steps.
First compile a mongoDB extension using PECL. We have a How-To guide on how to compile your own mongoDB extension.
Download the MongoDB Community Edition. After downloading you should find a mongodb-osx-xxxx.tgz file. Uncompress this file and you should have the following directory structure.
Move your mongodb-osx-ssl-xxxx directory to /usr/local
, resulting in /usr/local/mongodb-osx-ssl-xxxx
. Create a /data/db
directory to hold your MongoDB data. This is the default location for MongoDB data. Additional installation instructions can be found here.
Open a terminal window to run MongoDB. Navigate to /usr/local/mongodb-osx-ssl-xxxx/bin
directory and type the following to start your MongoDB server.
In addition to the MongoDB extension you will need the MongoDB library. Use Composer to install the MongoDB library. Information on downloading composer can be found here. Scroll down and click on “download this file” for OS X. This should download an “Installer” file to your downloads folder.
Next create a host. In a new terminal navigate to the document root of your new host. Move the Install file which you downloaded from the Composer website to your document root. Run the following commands in your terminal found in the Composer documentation as explained here.
Type the following in your terminal and press return.
Your document root should now look like the following.
Once you have installed this, you can use the following code example to insert into your new MongoDB database.