Home » Cpanel/WHM » How to Install MongoDB on CentOS and cPanel

How to Install MongoDB on CentOS and 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?

Originally posted 2016-02-18 22:47:49.

About admin

I have been working with Linux based systems since 2002. I hope the article published on this site will be useful to those new to server administration.