In order to execute code in PHP that interacts with the MongoDB server you should install the MongoDB driver in your PHP execution environment. Using MAMP, I spent lots of hours finding out that MAMP doesn’t come will all source code files of PHP in order to allow you building the mongo.so file. The mongo.so file is the Mongo extension we should create and place together with all other extensions in our PHP execution environment.

In order to overcome this problem, I chose to create the mongo.so using the XAMPP execution environment and then copy it to my MAMP execution environment. The video clip below overviews all steps, including the basic steps of installing MongoDB, turning on its serverand perform basic operations.

When adding the mongo.so file to your PHP execution environment make sure you don’t forget to update the php.ini file. The “extension=mongo.so” line must be added to it. In addition, make sure you restart the server before you test drive your code.

If you want to save time on your end and avoid the building process of the mongo.so file on your end, you might want to use the one I created. It works fine with PHP 5.6.10. This is the PHP version I am using.

XAMPP, MAMP & MongoDB

Leave a Reply

Your email address will not be published. Required fields are marked *