Skip to content
Jeffrey Arts edited this page Sep 8, 2023 · 10 revisions

Webserver setup

This document guides you through my personal preferred set-up for running my project web server, we take a fresh installation of Ubuntu 22.04 as the basis.

1) Install Packages

sudo apt-get update

# NGINX
sudo apt-get install nginx

# NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install 16

# PM2
npm install pm2 -g

# Yarn
npm install yarn -g

# Unzip
sudo apt-get install unzip

# Certbot

sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

2) Create Web Group and Add Users

sudo groupadd web
sudo usermod -a -G web ubuntu
sudo usermod -a -G web www-data
// Optional
sudo adduser <username>
sudo usermod -a -G web <username>

3) Setup Architecture

sudo mkdir /var/www/strapi
sudo mkdir /var/www/vite
sudo chown ubuntu:web /var/www/vite
sudo chown ubuntu:web /var/www/strapi

These scripts help to automate some steps for creating NGINX configuration files. Install them for the current user.

if [ ! -d ~/bin ]; then mkdir ~/bin; echo "export PATH=\$PATH:~/bin" >> ~/.bash_profile; fi && cd ~ && git clone https://github.com/JeffreyArts/nginx-helper-functions.git && cp nginx-helper-functions/* ~/bin/ && chmod +x ~/bin/* && source ~/.bash_profile

5) Prepare pm2 deployment

On default, Ubuntu doesn't allow to loading the entire .bashrc file. This is required though for succesfully running the pm2 deploy script. In order to make that script run succesfully, please comment out (or remove) the following lines in the ~/.bashrc file so they are no longer escaping the script when pm2 tries to load it.

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

Notes

NGINX Functions

sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo tail -f /var/log/nginx/access.log

# Test config file
sudo nginx -t

Add Local SSH Key to Remote Known Hosts

ssh-copy-id <user>@<host>