ScaleScaleScaleScale

Tips / Nginx


How to Install MongoDB on CentOS + cPanel

MongoDB is one of those technologies that you should be paying attention to because it’s changing the way that developers interact with databases.

MongoDB is officially a “NoSQL” database. Thanks to its architecture and BSON structure, it can scale more easily than other popular database servers like MySQL.

MongoDB helps you to integrate database information into your apps easier and faster. That’s why it’s becoming the number one NoSQL solution, chosen by many popular websites like eBay, NY Times, SourceForge and many others.

In this guide, you will learn how to install MongoDB on a WHM/cPanel WHM server.

Technical requirements

  • Root access via SSH
  • PHP-pear for full pecl support
  • PHP-devel package installed to compile extension manually

Installing MongoDB via MongoDB Repo

There are lot of RPM repos that offer MongoDB packages. It is recommended to always use the MongoDB official repo to get the latest stable and secure versions.

Install the MongoDB repo:

cd /etc/yum.repos.d

Create mongodb.repo file:

nano -w mongodb.repo

Paste this code inside:

[mongodb]
name=MongoDB Repo
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

Save the file by pressing CTRL + O to write the file, and then CTRL + X to exit.

Install MongoDB using Yum

yum install mongo-10gen mongo-10gen-server

At this point, you should have MongoDB installed on your CentOS + cPanel box.

Configure MongoDB to automatically start after reboot:

chkconfig mongod on

Start MongoDB:

service mongod start

Now, you should have the MongoDB system daemon fully running on your Linux environment. However, that’s not enough for most applications, as addressed by the second part of this tutorial,  installing the MongoDB app support for PHP.

Install MongoDB PHP Extension

Use the powerful PECL command to install your MongoDB PHP extension:

pecl install mongo

Restart Apache to apply changes:

service httpd restart

Verify installation with this command:

php -i | grep mongo -i

If you see the MongoDB extension in the output, then you are all set!

What if you don’t have the PECL command available?

There is an alternative way to install the MongoDB PHP extension by compiling manually. Example:

mkdir $HOME/mongo
cd $HOME/mongo
wget https://github.com/mongodb/mongo-php-driver/zipball/master
unzip master
cd mongodb-mongo-php-driver-07be50e/
phpize
./configure
make install

Add the extension to your /usr/local/lib/php.ini file:

extension=mongo.so

Restart Apache to ensure that this module is recognized by the web server:

service httpd restart

Again, check against PHP to ensure that it is fully loaded:

php -i | grep mongo -i

What are your experiences working with MongoDB? Do you notice any difference when comparing this software with MySQL or other traditional SQL solutions?

Popular search terms:

  • https://www scalescale com/tips/nginx/mongodb-centos-cpanel/
  • Cent OS whm mongodb
  • mongodb cpanel
  • cpanel and nosql
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Luann Ebert

    Hi,
    I think the code provided for the mongodb.repo is misleading. the first line should be split into two:
    [mongodb]
    name=MongoDB Repo

    If used as shown, the install process aborts with error.

    otherwise, very helpful … thanks

    • @Luann, thanks for reporting that error, it has been corrected.

  • Pradeep Bisht

    Install MongoDB PHP Extension successfully …. thanks buddy

  • Santiago Gonzalez

    Thank you for such a great explanation! It worked perfectly 🙂

  • server management

    Thanks for the installation steps. Got it successfully installed.
    php -i | grep mongo -i
    mongo
    MongoDB Support => enabled
    MONGODB-CR => enabled
    MONGODB-X509 => enabled
    mongo.allow_empty_keys => 0 => 0
    mongo.chunk_size => 261120 => 261120
    mongo.cmd => $ => $
    mongo.default_host => localhost => localhost
    mongo.default_port => 27017 => 27017
    mongo.is_master_interval => 15 => 15
    mongo.long_as_object => 0 => 0
    mongo.native_long => 1 => 1
    mongo.ping_interval => 5 => 5

    Can the default port be changed ?

    • Edit /etc/mongod.conf and set the “port=” variable as you like. Then restart MongoDB service to apply changes.

  • Timothy Williams

    Awesome..It really works. Thanks for the post.