Applicable to:
- Plesk for Linux
How to install MongoDB in Plesk?
Answer
Plesk does not support MongoDB database servers.
All supported Third-Party components can be found in Plesk Software Requirements.
As an alternative, MongoDB can be deployed in local or remote Docker container:
Warning: Below steps are done on your own risk! Even being installed via Docker. MongoDB should still be managed manually, Plesk has no controls to manage it (creating DBs, etc.).
Note: Local Docker service is not supported on Windows and CloudLinux. For more information refer to the Plesk Administrator's Guide.
Note: Installing MongoDB as a Docker container on Ubuntu 22.04 is not possible because the mongodb-clients
package is not available on this OS and it would be unable to communicate with the container
- Log in to Plesk
-
Navigate to Plesk > Docker
-
Type
mongo
in the Docker catalog search field: -
Click on Run button to automatically download and start MongoDB instance deployment:
-
Disable Automatic port mapping and manually map MongoDB instance to the localhost port:
Note:
External
port is the port on which all connections to MongoDB will be served.Warning: If port mapping is configured, Docker binds to the specified port on all network interfaces of the host system. This means the MongoDB instance will be accessible from anywhere, and additional firewall rules should be created to limit access if necessary.
-
Map Docker container to location on file system, to ensure that both data and configuration will survive Docker container restarts:
-
Add the variables MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD to be able to change root password:
-
Click OK to deploy and start the Docker container:
-
Connect to Plesk server via SSH ;
-
Verify that MongoDB is listening for incoming connections:
# ss -tlpn | grep 27017
LISTEN 0 128 :::27017 :::* -
Install MongoDB shell:
-
For .deb-based OS (Debian, Ubuntu):
# apt install -y mongodb-clients
-
For .rpm-based OS (RHEL, CloudLinux, CentOS):
# echo -e '[mongodb-org-4.0]\nname=MongoDB Repository\nbaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/\ngpgcheck=1\nenabled=1\ngpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc' >> /etc/yum.repos.d/mongodb.repo
# yum install -y mongodb-org-shell
-
-
Verify MongoDB connectivity from the localhost by running mongo shell on the Plesk server:
# mongo
MongoDB shell version: 2.6.10
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
>
Comments
28 comments
Hi Robert, i have done what you say and I get the following error, what can it be?
Error: {"message":"driver failed programming external connectivity on endpoint mongo (ee36c8720ed12a1cd8b3cac64bdcd552544415f64be1ea0e6b998ebf49fd75c6): (COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -A DOCKER ! -i docker0 -o docker0 -p tcp -d 172.17.0.2 --dport 27017 -j ACCEPT' failed: iptables: No chain/target/match by that name.\n)"}
Thanks!!
Hello @Alvaro, as I can see the same error was discussed here: https://talk.plesk.com/threads/docker-doesnt-start-any-single-image-iptables-error-bug.341757/
As a resolution, the server was restarted, have you tried it?
Another workaround was discussed here: https://github.com/moby/moby/issues/1871
Thanks @Ivan, one last question, how to enable the auth on the mongodb instance?
With the enviroment variable AUTH = yes ?
Hello @Alvaro,
Please, check this link.
If it would not help, contact the container developers.
How can i configure mongo shell? If i type mongo the shell tell me to install mongo from apt.
Thanks
@Mattia Di Giuseppe
The shell client has to be installed on the host server indeed. You may do it as follows:
Article was updated to mention it.
@Alexandr Bashurov
Yes I have fixed it but now I have problems with web client for Mongo. I have installed pecl extension but any of web clients works. Can u help me? Thanks
@Mattia Di Giuseppe
Hi! You may search for any errors in log files and check them in our KB articles or MongoDB documentation. You may also contact MongoDB support since they are experts in MongoDB and can help you with the setup.
When following this example running plesk on Debian 8, I am faced with authentication errors when running the mongo shell via ssh. Either that authorisation is required or that the authentication mechanism is not defined??
@James Scholey
Hi! Try to login with: mongo -u user -p password --authenticationDatabase admin
***** UPDATE 20-07-2019 *****
Plesk team fixed the issue on their guide . You can fallow again the guide and the variables they mention.
****** BIG WARNING ******
If you dont do this, all your database data will be DELETED
On step # 5. Map Docker container to the location on filesystem, to ensure that both the data and the configuration will persist:
The image presented on this GUIDE is not updated, so add the same variables also on the second column (host column)
This will create on your file system the Database DATA and it will be read and not deleted from there.
**please plesk support UPDATE this GUIDA, i just lost many of my clients data because of this.
Hello @Daniel Vengoechea,
Thank you for your input.
The article was modified accordingly.
@Daria,
Your image and the image that @Daniel Vengoechea posted don't match up exactly.
Can you confirm that we need to follow your image and not his?
Thanks!
Рello @Chris Williams,
Thank you for your question.
The image, which is provided in the article, is the correct one.
Before posting all actions and images it was double checked on the test environment.
Actually, the warning post by @DANIEL VENGOECHEA is correct somehow, even though I am not facing any data loss issue, but a login issue. I have tested it here with and without the variables after the 2nd rows. (like he mentioned above)
I was facing an authentication error when trying to log in. But after changing the directories as he said. I managed to log in from SSH, and Mongo Compass.
I double-checked by switching back to only 2 rows of (Map Docker to the filesystem) and log in again. Failed due to Authentication Error. and cannot show dbs.
Anyway, thanks for this helpful post and helpful community. I managed to connect it :)
Hello @Thomas Kim,
Thank you for your input!
Glad to hear that the issue was solved!
I have followed all of the steps in the guide and was successfully able to set up mongodb.
However, I am having issues with authentication from my NodeJS App, setup similarly to this: (https://www.plesk.com/blog/product-technology/node-js-plesk-onyx/)
I can not pass authentication checks from my app or by mongo shell in ssh
db.auth("user", "pass");
Removing these from the Docker image makes everything work:
MONGO_INITDB_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD
But I am obviously not password protected anymore.
Since I am using MongoDB via the Docker, and the database is set up on localhost, is it safe to not set a password?
If a password is recommended do you know how I can pass the authentication checks?
Thank you very much.
Hello @Cbordon,
>> Since I am using MongoDB via the Docker, and the database is set up on localhost, is it safe to not set a password?
It is not safe and we highly recommend to set the root password.
>> If a password is recommended do you know how I can pass the authentication checks?
To authenticate with root login and password use the following command via SSH:
mongo admin -u root -p yourpassword
At first, you should create the database:
use testdb
Then add the user to this database:
db.createUser(
{
user: "testuser",
pwd: "12345678",
roles: [
{ role: "read", db: "testdb" }
]
}
)
Then it will be possible to authenticate this user:
db.auth("testuser", "12345678");
1
Note: db.auth() returns 0 when authentication is not successful, and 1 when the operation is successful.
Please refer to the following articles for more information:
https://docs.mongodb.com/manual/tutorial/create-users/
https://docs.mongodb.com/manual/reference/method/db.auth/
Thank you for your timely reply.
Following these instructions gave me a different authentication error:
Error: couldn't add user: not authorized on testdb to execute command { createUser......
@Cbordon
Seems that you need to create admin user, and then create testuser under admin. Check the following thread.
The rated answer mentions accessing mongod without --auth
Following the instructions on this page, it didn't require me to install mongod.
Is that something I should add? If so, how would I go about doing that on plesk server?
I was finally able to create a user.
I ended up using @Daniel Vengoechea's answer and all of my authentication checks started passing.
Thank you for your help!
What happened to the promise made in 10th of june 2019?
I'm a long time customer but starting to wonder if I should leave this sinking ship. Plesk mostly supports old technology and is missing out on all the "new". MongoDB, Redis, push mail, just to name a few are not natively supported. Git is just half baked in, no decent admin UI.
Are you a web developer mostly using old technology like Wordpress than Plesk is great, other than that you're on your own. Plesk built for developers? Meh.
Hola @DANIEL VENGOECHEA
Gracias por tu aporte ya funciona mongo como es debido, estuve revisando porque me fallaba la autentificación, pero con tu aporte me funciono perfectamente, deberían de incluirlo en la guía, ya que desde hace 2 AÑOS estaba este problema y todavía no está actualizada la guía.
¡Gracias Dani!.
Un saludo
Step 11 not working for Ubuntu 22.04
Hi,
How can i mongo dump and restore using mongo docker.
Is there anyother steps available?
it would be great if there is a easy way to get the mongoDB to be backed up.
Like setup a Cron to dump DB to a given plesk domain folder
Your guide is outdated and will not work for UBUNTU 22.04
No mention about security and no instruction how to possible backup the database
Please sign in to leave a comment.