Skip to main content

Command Palette

Search for a command to run...

Configure MERN Stack on Dedicated Cloud or VPS

Published
2 min read
Configure MERN Stack on Dedicated Cloud or VPS
A

Building LMS Backend

  1. Set up a Dedicated Server or (VPS) on a cloud provider such as AWS, Azure, or Google Cloud.

  2. Install Ubuntu Server on Dedicated Server

  3. Install and configure MongoDB on the Server. This will be used as the database for your application.

# Add Key
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

# Install MongoDB
sudo apt-get update
sudo apt-get install -y mongodb-org

# start mongodb
sudo systemctl start mongod

# set mongodb to start automatically on system startup
sudo systemctl enable mongod
  1. Install Node Js
# add nodejs 10 ppa (personal package archive) from nodesource
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

# install nodejs and npm
sudo apt-get install -y nodejs
  1. Set up a process manager, such as PM2, to keep the application running in the background.
# install pm2 with npm
sudo npm install -g pm2

# set pm2 to start automatically on system startup
sudo pm2 startup systemd
  1. Use a reverse proxy such as Nginx to handle incoming traffic and route it to the Node.js application.
# install nginx
sudo apt-get install -y nginx
  1. At Last Setup Your Firewall
# allow ssh connections through firewall
sudo ufw allow OpenSSH

# allow http & https through firewall
sudo ufw allow 'Nginx Full'

# enable firewall
sudo ufw --force enable

It is important to note that this is a high-level overview of the steps and there are many details and security considerations to take into account when deploying to a production server. It is recommended to consult the documentation of each technology and best practices for deploying production applications.

Subscribe to me on Youtube for more updates