Install MongoDB on DirectAdmin Jun 21, 2017

MongoDB

This article is for DirectAdmin with CentOS 7 runs on Vultr's Cloud VPS

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 login

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

If you want 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" } ]
     }
)

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 https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/

Mission completed!

 

Advertisement

Latest Updates