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:

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

Add the text below and save:

[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:

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

Config MongoDB

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

mongo

Then, in the mongo CLI, run those commands:

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

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

security:
  authorization: enabled

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

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:

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):

/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.

Comments