Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raymanaa/0cae8afd6b5ee7b9b3ed1df7a3b870ab to your computer and use it in GitHub Desktop.
Save raymanaa/0cae8afd6b5ee7b9b3ed1df7a3b870ab to your computer and use it in GitHub Desktop.
Setup Node.js + MongoDB Production Server on Ubuntu 18.04 - http://jasonwatmore.com/post/2018/09/26/setup-nodejs-mongodb-production-server-on-ubuntu-1804
#!/usr/bin/env bash
# Set NODE_ENV permanently to production in Ubuntu:
#$ sudo nano /etc/environment
#Append the following at the end of the file:
#NODE_ENV=production
echo "
----------------------
NODE & NPM
----------------------
"
# add nodejs 12 ppa (personal package archive) from nodesource
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
# install nodejs and npm
sudo apt-get install -y nodejs
echo "
----------------------
MONGODB
----------------------
"
# import mongodb 4.2 public gpg key
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
# create the /etc/apt/sources.list.d/mongodb-org-4.0.list file for mongodb
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
# reload local package database
sudo apt-get update
# install the latest version of mongodb
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
###
# Check https://github.com/CodepediaOrg/bookmarks.dev/wiki/MongoDB-Setup-for-Production for Mongo configs etc...
###
echo "
----------------------
PM2
----------------------
"
# install pm2 with npm
sudo npm install -g pm2
# set pm2 to start automatically on system startup
sudo pm2 startup systemd
echo "
----------------------
NGINX
----------------------
"
# install nginx
sudo apt-get install -y nginx
echo "
----------------------
UFW (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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment