
The short answer: MongoDB is a database that stores documents (like JSON) instead of tables. It is not part of cPanel’s database tools, so you run it on a VPS. The rule that matters most: never leave it open to the internet. Many unprotected MongoDB servers have been wiped and held to ransom by whoever found them.
The simplest way: a container
If you already use Docker (see Running Docker on a VPS safely), the official image gives a clean install that is easy to remove:
docker run -d --name mongo --restart unless-stopped \
-p 127.0.0.1:27017:27017 \
-v mongo-data:/data/db \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=A-STRONG-PASSWORD \
mongo
| Part | What it is for |
| -p 127.0.0.1:27017:27017 | The most important. Publishes the port on the VPS itself only. Without 127.0.0.1, Docker opens it to the world, even with the firewall on. |
| -v mongo-data:/data/db | Keeps the data in a volume, so you do not lose it when the container is recreated. See Docker volumes or bind mounts. |
| MONGO_INITDB_ROOT_* | Creates the administrator user and switches authentication on. Use a long password; see A strong password and a password manager. |
Use a numbered version instead of mongo alone, so an update does not catch you by surprise (the list is on the image’s page on Docker Hub).
Installed on the system
Without Docker, MongoDB is installed from MongoDB’s own repository for your Ubuntu or Debian version. Package and key names change with versions, so follow the official installation guide rather than copying old commands. Either way, after installing:
|
|
|
How the application connects
An application on the same VPS connects with an address like mongodb://admin:PASSWORD@127.0.0.1:27017/my-database?authSource=admin. Keep it in the application’s configuration file, outside the code: see Keeping passwords out of your code. To look at the data from your computer, use an SSH tunnel instead of opening the port: ssh -L 27017:127.0.0.1:27017 user@VPS-IP, and connect to localhost.
Backups
Use mongodump to make the copy: mongodump --uri="mongodb://..." --gzip --archive=/backups/mongo.gz; and mongorestore to put it back: mongorestore --uri="mongodb://..." --gzip --archive=/backups/mongo.gz. Run it from cron and send the copy off the server: see Off-site backups. And test the restore, not only the copy.
| If your MongoDB was ever open to the internet, treat it as compromised: change all passwords, check for data that is missing or extra, and restore from a clean copy. See Keeping your VPS secure. |
|
Want help deciding whether MongoDB suits your application, or locking it down? Open a ticket saying what you will store. Open a support ticket |
RECOMMENDED PRODUCT VPS server with root access Resources of your own, the OS you choose, reinstall whenever you like. from 7.560,00 Kz/mo (3-year plan, with coupon) See plans |
- 0 Users Found This Useful











