Installing MongoDB on cPanel / WHM / CentOS along with the PHP extension


Attempts to install MongoDB on a cPanel based CentOS VPS

While trying to install MongoDB on a cPanel based CentOS server, I found the system configurations were customised by cPanel. And because of which a lot of commands were not available in bash. Also the installation of some packages was disabled in the /etc/yum.conf (e.g. php* in the ‘exclude’ list blocked the installation of php-devel package, etc.). This is a documentation of the key steps to install MongoDB on such a system.

I referred the official doc on to install mongodb on CentOS. So at the time of writing this, the version provided in the doc to install was 4.4.

Please note that I did the installation as ‘root’ user.


1.Create a repo file in /etc/yum.repos.d called mongodb-org-4.4.repo with this content:

name=MongoDB Repository

2. Install the MongoDB packages

yum install -y mongodb-org

3. Configure MongoDB to auto-start on system startup / reboot

chkconfig mongod on


Note: Forwarding request to 'systemctl enable mongod.service'.

4. Start MongoDB

service mongod start


Redirecting to /bin/systemctl start mongod.service

5. Install MongoDB PHP Extension

Note that cPanel has the tools like pecl, phpize, etc. in the following location. Change the version in “ea-php*” as per your PHP version. There could be multiple versions of PHP installed, so choose the version you are using for the project.


So to run phpize followed by ./configure while compiling a package yourself, use something like:

/opt/cpanel/ea-php74/root/usr/bin/phpize && ./configure --with-php-config=/opt/cpanel/ea-php74/root/usr/bin/php-config

PHP extension installation with the pecl tool:

/opt/cpanel/ea-php74/root/usr/bin/pecl install mongodb


Note that some references ask to install ‘mongo‘ as the extension, but it is the old extension, and with PHP 7 you need to install ‘mongodb‘ as the extension.

A successful installation should end with something like:

Build process completed successfully
Installing '/opt/cpanel/ea-php74/root/usr/lib64/php/modules/'
install ok: channel://
Extension mongodb enabled in php.ini

Info: Location of php.ini on cPanel:


6. Restart Apache

service httpd restart

Leave a Reply

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