Let's host the MongoDB Database on the VPS server. Follow the simple steps:

First login to your VPS server by using the created user or root user. Suppose you don't created yet, click here to create a user on vps Server using simple steps.

Let's login first:

Using ssh: by passing ip address or VPS root user password.

login to my vps using ssh

After login change the user if you want to host the website without interpreting the admin permissions safely.

Last time we created a user you can check here, click here. So i am going to change the user from root user to created user.

By using command:

su user_name

In my case:

su theagleye

Now it looks like:

root@srv691477:~# su theagleye
theagleye@srv691477:/root$

 

After doing this, now simply copy past some commands:

Update and Upgrade Your VPS Server

sudo apt update

Note : If it asks for password, enter the password. it ask only for one time. The password is of root user passsword.

sudo apt upgrade -y

 

Install MongoDB:

sudo apt-get install gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor

Create the MongoDB list file.

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

Update package lists and install MongoDB.

sudo apt-get update
sudo apt-get install -y mongodb-org

 

Start and enable MongoDB service.

sudo systemctl daemon-reload
sudo systemctl start mongod
sudo systemctl enable mongod

 

Verify that MongoDB has started successfully.

 sudo systemctl status mongod

If you getting something like this in your terminal. It means you successfully install MongoDB in your VPS server.

mongodb setup on vps done


 

Allowing MongoDB through firewall so that MongoDB nicely allowing to work on Server:

Enable firewall:

sudo ufw enable

Check Port is Allowed through Firewall

sudo ufw status

If Port is not Allowed then Allow it through Firewall

sudo ufw allow 27017
sudo ufw allow 'OpenSSH'

Restart MongoDB:

sudo service mongod restart

 

Leave a comment

You must be logged in to post a comment.

0 Comments