Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevenup/9fbe236b8879ab540ea5aaeb5ca14821 to your computer and use it in GitHub Desktop.
Save stevenup/9fbe236b8879ab540ea5aaeb5ca14821 to your computer and use it in GitHub Desktop.

Revisions

  1. @cornflourblue cornflourblue revised this gist Oct 10, 2018. No changes.
  2. @cornflourblue cornflourblue revised this gist Oct 10, 2018. No changes.
  3. @cornflourblue cornflourblue revised this gist Oct 10, 2018. No changes.
  4. @cornflourblue cornflourblue created this gist Sep 26, 2018.
    77 changes: 77 additions & 0 deletions setup-nodejs-mongodb-production-server-on-ubuntu-1804.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    #!/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