Skip to content

Instantly share code, notes, and snippets.

@anistark
Last active January 27, 2024 11:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anistark/2609575a4c5070080da46c4d8c8fc3be to your computer and use it in GitHub Desktop.
Save anistark/2609575a4c5070080da46c4d8c8fc3be to your computer and use it in GitHub Desktop.
Server Setup

Setting Up Basic NodeJs Server with Postgres

sudo apt update
sudo apt upgrade
sudo apt install -y vim tree tmux npm git

Node v20
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs

Node v18
curl -sL https://deb.nodesource.com/setup_18.x | sudo bash -
sudo apt -y install nodejs

Node v16
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
sudo apt -y install nodejs

Node v12
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

sudo apt install build-essential
sudo apt update

Setup go:

sudo apt install golang-go
wget -O ~/.tmux.conf https://gist.githubusercontent.com/anistark/1f686bab54e93d1941f9/raw/8962c23f8d897510cce6b9f722a720d53210dcf7/tmux.conf

Setup tmux.conf

Setup bash_profile

source ~/.bashrc
source ~/.bash_profile

Setup Redis.

sudo apt install redis-server -y

Setup NGINX

sudo apt update
sudo apt install nginx
sudo ufw status
sudo systemctl enable nginx

Full Setup NGINX

Setup Postgres

sudo apt install postgresql postgresql-contrib -y
sudo -u postgres psql

Create user with password: CREATE USER ani WITH PASSWORD '123';

Refer Postgres Full Setup

Setup pm2

pm2 start -i 4 --name="appName" npm -- start

Setup forever

forever start app.js

Setup virtualenv

sudo apt update
sudo apt install python-virtualenv

Setup Certbot

sudo apt install certbot python3-certbot-nginx -y

Run Certbot (after app installation):

sudo certbot --nginx

Check certbot autorun: sudo systemctl status certbot.timer Ref Full Setup

Common Errors Encountered:

  • In case of failed install to overwrite a debian package, you have to force overwrite the files causing issues: sudo dpkg -i --force-overwrite <file-path>. Then check if everything is fixed by running: sudo apt-get --fix-broken install Usually might happen for node 18 install. sudo dpkg -i --force-overwrite /var/cache/apt/archives/nodejs_20.5.0-deb-1nodesource1_amd64.deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment