App Server Setup
Setup a Node / Express, Nginx, PM2, Postgres App Server
1. Pre-Steps
Build an Linux server first. See Gist Ubuntu Server Setup https://gist.github.com/julian-iFactory/f24cc00c9e8b1984139340391c58680e
SSH into server as non-root user - typically 'ifactory'
Have password for non-root user as its requested the first time 'sudo' is used
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 ]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:
4. Setup Postgres
Note: there is two different postgres users. Both callsed 'postgres':
Linux user 'postgres' - Used to administer the database typically fromt the bash command line
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?
