This updated guide walks you through the latest method to install and configure MongoDB on a cPanel server. While cPanel doesn’t natively support MongoDB, you can manually install it for your applications using root access. Follow these steps to ensure a smooth integration.

Although cPanel primarily supports MySQL and MariaDB, developers often require MongoDB for NoSQL applications. With the right configuration, you can set up MongoDB on your cPanel server, even though it’s not officially supported by cPanel.

Prerequisites

  • Root SSH access to your server
  • cPanel & WHM installed on a CentOS or RHEL-based distribution
  • Basic command-line proficiency

Step 1: Add the MongoDB Repository

Begin by creating a MongoDB repository file to ensure you install the latest stable version:

# Navigate to the yum repository directory
cd /etc/yum.repos.d/

# Create and edit the MongoDB repository file
nano mongodb.repo

Add the following content to the file:

[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc

Save and exit the file.

Step 2: Install MongoDB

Now, install MongoDB using the package manager:

# Clean the yum cache
yum clean all

# Install MongoDB
yum install -y mongodb-org

The installation will include the following key components:

  • mongodb-org-server: The mongod daemon
  • mongodb-org-mongos: The mongos daemon
  • mongodb-org-shell: The MongoDB shell
  • mongodb-org-tools: Backup and monitoring tools

Step 3: Start and Enable MongoDB

Once installed, start MongoDB and configure it to start at boot:

# Start MongoDB
systemctl start mongod

# Enable MongoDB at startup
systemctl enable mongod

Check if MongoDB is running:

# Verify MongoDB status
systemctl status mongod

Step 4: Install the MongoDB PHP Extension

For PHP-based applications, install the MongoDB PHP extension:

# Install dependencies
yum install -y php-pear php-devel

# Install the MongoDB extension
pecl install mongodb

Enable the extension by adding it to your PHP configuration:

# Enable the MongoDB extension
echo "extension=mongodb.so" > /etc/php.d/30-mongodb.ini

Restart Apache to apply the changes:

# Restart Apache
systemctl restart httpd

Important Considerations

Since cPanel does not officially support MongoDB, keep in mind the following:

  • Future cPanel updates might affect MongoDB compatibility.
  • Official cPanel support does not cover MongoDB-related issues.

For production environments, consider using an external MongoDB service or hosting it separately to avoid conflicts.

For additional support, visit @CustomerPanel or check cPanel’s documentation: cPanel MongoDB Support.