App Server Setup

Setup a Node / Express, Nginx, PM2, Postgres App Server

1. Pre-Steps

  1. Build an Linux server first. See Gist Ubuntu Server Setup https://gist.github.com/julian-iFactory/f24cc00c9e8b1984139340391c58680e

  2. SSH into server as non-root user - typically 'ifactory'

  3. Have password for non-root user as its requested the first time 'sudo' is used

  4. Makre sure server is up to date

$ sudo apt update   [ Ensure package manager is up to date ]

2. Setup NodeJS

$ cd ~
$ curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh   [ Download Node V14 into users directory ]
$ sudo bash nodesource_setup.sh                                           [ Run node setup script. Enter password for user. ]
$ sudo apt install nodejs                                                 [ Install node ]
$ node -v                                                                 [ Check node version ]
$ npm -v                                                                  [ Check npm version ]
$ sudo apt install build-essential                                        [ Install node build essential - required for some npm packages ]

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-20-04

3. Setup PM2

This previous command generates the next command to run. Example output below for 'ifactory'.

To remove the PM2 startup script:

For more information on PM2 configuration:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-20-04

4. Setup Postgres

Note: there is two different postgres users. Both callsed 'postgres':

  1. Linux user 'postgres' - Used to administer the database typically fromt the bash command line

  2. Database user 'postgres' - Used this to login to database and perform SQL commands etc. Apps use this user.

A. Install Postgres

B. Change User Passwords

C. Allow Remote Connections

Check firewall allows connections over default Postgres port 5432:

Allow Postgress to listen to external connections:

Add a line below in the 'CONNECTIONS AND AUTHENTCIATION' section :

Open config file

Comment out old line and add new line

Exit and restart postgres

Resources https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-20-04-quickstart https://www.linode.com/docs/guides/how-to-install-postgresql-on-ubuntu-16-04/

5. Setup Nginx

A. Set ownership and permssions of www folder

B. Create website/app location

https://unix.stackexchange.com/questions/182212/chmod-gs-command

C. Install & Configure Nginx

Related Commands

https://www.linode.com/docs/guides/how-to-install-nginx-ubuntu-18-04/

Was this helpful?