Install MongoDB on DirectAdmin

DirectAdmin MongoDB
DirectAdmin MongoDB

Introduction

This guide shows you how to install MongoDB on your DirectAdmin server.

Prerequisites

  • Basic knowledge of Linux OS.
  • A running DirectAdmin Server.

Install MongoDB

SSH to your server with root and run:

bash
nano /etc/yum.repos.d/mongodb-org.repo

Add the text below and save:

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

Next, run the following commands:

bash
yum repolist
yum -y install mongodb-org
systemctl start mongod

Config MongoDB

First, we enable authorization for MongoDB, run this command:

bash
mongo

Then, in the mongo CLI, run those commands:

bash
use admin
db.createUser(
     {
          user: "admindb",
          pwd: "YOUR_PASSWORD",
          roles: [ "root" ]
    }
)
exit

Next, we edit MongoDB config /etc/mongod.conf file and add:

txt
security:
  authorization: enabled

Now restart MongoDB, and you can use your account to log in:

bash
mongo --port 27017 -u "admindb" -p "YOUR_PASSWORD" --authenticationDatabase "admin"

If you want to create more accounts for your users, just run the commands below:

bash
use userdb
db.createUser(
     {
          user: "username",
          pwd: "USER_PASS",
          roles: [ { role: "readWrite", db: "userdb" } ],
          mechanisms:["SCRAM-SHA-1"]
     }
)

Install MongoDB PHP Driver

Just run this command (replace 71 with your desired PHP version, if any):

bash
/usr/local/php71/bin/pecl install mongodb

Then add "extension=mongodb.so" to php.ini and restart PHP/Apache for changes to take effect.

Disable Transparent Huge Pages (THP)

See MongoDB doc

Conclusion

You have now installed MongoDB on your DirectAdmin server.

If you found this useful, you can buy me a coffee! Thanks for the support!