Install MongoDB on cPanel + CentOS Linux

Question: how can I install MongoDB on cPanel servers using CentOS?
Answer: MongoDB can be installed using the classic RPM packages. On this post we will explore how to install MongoDB on cPanel servers using CentOS operating system.


MongoDB is a nice alternative to the classic MySQL Server, it’s a different kind of approach to what we know about databases and how programmers interact with them.

MongoDB is a “NoSQL” database that is becoming really popular between developers. Allows integration faster and easier than most database servers. Its architecture is based on BSON, which allow developers to extends the JSON classic model to provide additional ordered fields, data types, and better efficiency while decoding and encoding using different languages.

MongoDB Requirements

PHP-Pear can be installed using EasyApache from cPanel, while PHP-Devel comes enabled by default on every cPanel server.

  • PHP-Pear Package installed.
  • PHP-Devel Package installed.

Step by step: Install MongoDB on cPanel

Installing MongoDB via MongoDB Repo is pretty much easy, you only need to setup the mongodb repository, and then issue the dnf command to install the MongoDB server. Let’s begin.

Create the MongoDB repo:

nano -w /etc/yum.repos.d/mongodb.repo

Copy and paste this code inside:

name=MongoDB Repo

Press CTRL + X, then press Y to save the file and exit.

Install MongoDB using DNF

dnf install mongo-10gen mongo-10gen-server -y

This commandw will install MongoDB server on your cPanel dedicated or vps server.

Let’s enable MongoDB to start after reboot:

For CentOS 6:

chkconfig mongod on

For CentOS 7:

systemctl enable mongodb.service

Start MongoDB service:

On CentOS 6:

service mongod start

On CentOS 7:

systemctl start mongod

At this time you should have your MongoDB daemon service running inside your CentOS Linux server.

Installing MongoDB PHP Extension

You already have MongoDB system daemon running, but that is the system service, now you need to install MongoDB PHP Extension in order to connect from PHP to MongoDB database server. Let’s install the MongoDB support for PHP.

Enable MongoDB PHP Extension

For this we will use PECL installer, type this command:

pecl install mongo

The output should be something like this:

[[email protected]:~] pecl install mongodb
downloading mongodb-1.2.5.tgz ...
Starting to download mongodb-1.2.5.tgz (784,141 bytes)
Build process completed successfully
install ok: channel://
You should add "" to php.ini

Apply the changes by restarting your Apache HTTP server:

service httpd restart

Check that MongoDB PHP extension is loaded

php -i | grep mongo -i

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

Output example:

[[email protected]:~] php -i | grep mongo -i
MongoDB support => enabled
MongoDB extension version => 1.2.5
MongoDB extension stability => stable
mongodb.debug => no value => no value

All done. At this time you should know the neccessary steps to install MongoDB on cPanel using CentOS Linux, and the same applies to the MongoDB PHP extension

Further reading:

About the Author: Martin Keler

Leave a Reply

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