If you’ve been reading up on the various NoSQL offerings and have wanted to try out one but don’t know how to get started, this is one of the easiest ways. I chose MongoDB for this example because I’m going to start using it for a project that needs features that MySQL isn’t as fast at: namely denormalized data with billions of rows. MongoDB has plenty of drivers for other scripting and high-level languages but I’ll focus on the PHP driver today. If there is interest I can do a write up on Python usage later. This example is limited to CentOS, Fedora, and Redhat 5 servers that use the yum package management system. For more information you can reference their download page: http://www.mongodb.org/display/DOCS/Downloads
First install the prerequisites:
- sudo yum install gcc php php-pear
Then install the mogo php extension via pecl and add the extension to the ini file. (Increase the php.ini memory_limit to 32M if necessary). Then we restart apache to have the extension loaded. You can check your extensions via the phpinfo(); command in php.
- sudo pecl install mongo
- sudo echo “extension=mongo.so” >> /etc/php.ini
- sudo /etc/init.d/httpd restart
For the last part we add the yum repo and get the actual MongoDB server and client installed
- cd /etc/yum.repos.d
- sudo emacs mongodb.10gen.repo
- paste in the following. This uses the repo for 64bit servers. See their download page for other architecture repo settings.
- sudo yum install mongo-stable-server
- sudo /etc/init.d/monod start
- chkconfig mongod on
[10gen]
name=10gen Repository
baseurl=http://downloads.mongodb.org/distros/centos/5.4/os/x86_64/
gpgcheck=0
That’s it, you’re ready to start using Mongo! You can check the logfile to make sure things are running smoothly: “sudo cat /var/log/mongo/mongod.log”