This is a mini-post showing you how to get up and running with mongoDB and Zend Framework using a series of third-party libraries, including Shanty-Mongo library. To be honest, it’s rather trivial, but sometimes it can be frustrating trying to find a simple, concise, reference on how to do it, specific to just your needs.
This is really dependent on the platform that you’re on. The platform that I prefer for development is definitely Ubuntu. The latest stable release at the time of writing is 10.10. However there is a slight bug in the default mongoDB package for Ubuntu. You can find more detailed information here. But to summarise the process for getting mongoDB up and running quickly on Ubuntu, follow these instructions:
Let’s make it even simpler. Simply run the following after point one above:
sudo apt-get update && sudo apt-get install mongo-stable
Alternatively, you can go the more traditional route and download the source and the run the ./compile, make, make install and make test route. Personally, using a package manager such as APT is just so easy as the real focus of what we’re after here is to develop, not install packages. But there are and always will be, benefits to compiling it yourself.
Sometimes after installing, re-installing, or attempting to restart mongoDB on Ubuntu there is a lingering pid file that you need to remove and then restart mongoDB. After that you will have a running mongoDB daemon with no security set – so any user can no manage records through it. To test this, run the following command:
sudo netstat -tlnp | grep mongo
If you see a listing for mongo, then you’re ready to start working with it.
In the application configuration ini file (application/config/application.ini), add the following in the production section:
autoloaderNamespaces = 'Shanty_Mongo'
This has now made the Shanty-Mongo library available to your application.
Now in a development environment, adding security is not always necessary, but it can be good practice to enforce it right from the get-go. If you would like to read more about how to set it up, head on over to the Security and Authentication section of the mongoDB website.
Now Shanty-Mongo isn’t the only add-on library available for Zend Framework to work with mongoDB. Have a look at the list below for a range of alternatives.
You can find a list of PHP-based libraries, for use with the Zend Framework, as part of other projects and standalone at http://www.mongodb.org/display/DOCS/PHP+Libraries,+Frameworks,+and+Tools.
After that, you’re done and ready to go. You should follow-up this post by reading Coen’s excellent README either in the library, or via the project page on https://github.com/coen-hyde/Shanty-Mongo. It’s written in a very clear and logical manner and you’ll be up and running in no time at all. If you do have any troubles, please don’t hesitate to contact him, or contact us here at Malt Blue.
Have you heard about MapReduce? Want to use it in your Zend Framework project? Stay tuned for our next post when we extend on this one to start showing you just that!
If you liked what you read and would like to see more, please retweet it, or give it a like on Facebook or even give it some Digg love. And we always value you feedback and comments.