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.
Already know MongoDB?
Check out the follow up post on using mongoDB and Zend Framework to create a simple blog.
Installing mongoDB
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:
- add deb http://downloads.mongodb.org/distros/ubuntu 10.10 10gen to /etc/apt/sources.list
- sudo apt-get update (I’m assuming that no errors occur)
- sudo apt-get install mongo-stable
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.
The case of the “Mysteriously lingering PID file”
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.
Shanty-Mongo Library
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.
Adding Security
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.
Available Third-Party Libraries
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.
Finishing Up
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.
Coming Soon
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!
I’ve been using mongoDB and Zend Framework to make a simple, replicatable filesystem. As it went well, I thought that I could quickly apply what I’d done to create an ultra-simple blog system. Read on to find out all about it.
The Zend Framework Bootstrap can be one of the key aspects of getting up and running quickly with the Zend Framework. Let’s make it easy.
Recently I was asked how to rename a file with the Zend Framework that used a Zend Form and Zend File element. They key requirement was that it should not be a hack or a kludged solution. So I thought I’d write a quick post to provide a simple example on how it was achieved.
Ok, we’ve established that with the Zend Framework, we need to do a bit more work than some of the other frameworks to get up to speed - but that’s not necessarily a bad thing - right?! But it can be a bit tedious and it’s something as professional developers, we want to automate away. So we’ve been addressing in this series how to do just that with a custom, extendable bootstrap class.
In the first part of the series we laid the foundation of our custom bootstrap class by creating a custom class directory structure, adding its namespace to the application ini and modifying the default application bootstrap so that it extends from it and had a look at the first component - caching.
Then, in the second part of the series, we built on the foundation laid in part one by creating plugin resources for the routing table, application navigation and the database connections - these being some of the most common tasks, usually, associated with a web-based application.
In this, the third and final part of the series, I’m going to finish up by looking at application placeholders and surprise, no not logging as originally promised, but pagination. As an added extra, we’re going to be using a key feature of Zend Application to make it a breeze.
Join the discussion
comments powered by Disqus