Last active
August 5, 2024 19:06
-
-
Save cornflourblue/f0abd30f47d96d6ff127fe8a9e5bbd9f 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo " | |
---------------------- | |
NODE & NPM | |
---------------------- | |
" | |
# add nodejs 10 ppa (personal package archive) from nodesource | |
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - | |
# install nodejs and npm | |
sudo apt-get install -y nodejs | |
echo " | |
---------------------- | |
MONGODB | |
---------------------- | |
" | |
# import mongodb 4.0 public gpg key | |
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 | |
# 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.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.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 | |
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 |
Thank you!
Thanks!
How do i remove it on ubuntu @cornflourblue?
Where do we set env variables like MONGODB_URI
Thank you for your work @cornflourblue !
I was looking for something simple since long time.
I just want to know how do you deal with errors in this bash script ?
Very nice thank you!!
Do you think of any modifications for newer versions of Ubuntu and Mongo ?
*thanks !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank u , good man!