How to install MongoDB on CentOS 5.4 / RHEL5 and interface with PHP 5

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.
  • [10gen]
    name=10gen Repository
    baseurl=http://downloads.mongodb.org/distros/centos/5.4/os/x86_64/
    gpgcheck=0

  • sudo yum install mongo-stable-server
  • sudo /etc/init.d/monod start
  • chkconfig mongod on

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”

6 thoughts on “How to install MongoDB on CentOS 5.4 / RHEL5 and interface with PHP 5

  1. Brian Hogg says:

    Thanks for this, made life easy getting this installed!

  2. nana says:

    [root@25115_2_71849_311688 yum.repos.d]# service mongod start
    /etc/init.d/mongod: line 25: /etc/sysconfig/mongod: No such file or directory
    Starting mongod: runuser: user mongod does not exist
    [root@25115_2_71849_311688 yum.repos.d]# [FAILED]

    PLEASE HELP? Centos 64-bit 5.5

  3. admin says:

    You probably need to make sure that the “mongod” user was created. You can check via: $> grep “mongod” /etc/passwd
    If there is no user then add the user via: $> useradd mongod

  4. Thanks… very helpful.

    FYI, this line has a typo: sudo /etc/init.d/monod start

    and should be: sudo /etc/init.d/mongod start

  5. vangel says:

    thanks I needed this it helped me speed up my install. barring for the fact that maybe you should publish an updated version for this. It would help a lot of lost folks. minor things changed which isnt hard to figure out anyway.

    thanks for the time to publish this.

  6. [...] en Mattreid Etiquetado con: mongoDB, noSQL Publicado en: Bases de Datos, Desarrollo Web [...]

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>