/ Docs

Deploying to a VPS

Recommended
~5$/month

This runs the app with pm2 on the machine directly. The setup is easier but less secure.

Script installs and runs the web client, API and PV. If you want just the web client move to manual installation steps.

install.sh works on debian based distros only, for now. If you're running any other system move to manual installation steps and find replacements for the used packages.

Requirements:

  • a VPS
  • Fully qualified domain name

OPTION 1. Install script ( Recommended )

1. SSH into your VPS and create an empty folder in your home directory, ex. mkdir khofly

2. cd khofly and type git clone https://github.com/cufta22/khofly.git .

2.1. Pick a branch, by default it will be on master but if you want more frequent updates git fetch origin staging and git checkout -b staging origin/staging

3. Once the code is fetched, make sure that you can execute the install script chmod +x ./scripts/install.sh

3.1. Don't blindly trust any script you pull from the internet, you can inspect it with cat ./scripts/install.sh

4. Now you can run the script with sudo ./scripts/install.sh, if you didn't get any errors the installation was successful.

5. Edit the .env file for web ( nano ./web/.env.local ) values per provided comments.

6. Edit the .env file for api ( nano ./api/.env.local ) values per provided comments.

7. Edit the .env file for pv ( nano ./pv/.env.local ) values per provided comments.

8. Run ./scripts/update.sh to rebuild the everything since we changed the env files.

9. cd /etc/nginx/sites-available/ and edit the domain names for web and api files, and whatever other Nginx config you want to add.

10. Add SSL certificate for your domain certbot --nginx

11. sudo systemctl reload nginx

OPTION 2. Manual installation

1. Install dependencies

apt update && apt upgrade
apt install build-essential libssl-dev unzip nginx certbot python3-certbot-nginx ffmpeg

2. Install NVM

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source ~/.bashrc
nvm install 25

3. Install pnpm

curl -fsSL https://get.pnpm.io/install.sh | sh -

4. Install pm2

npm install pm2 -g
source ~/.bashrc

5. Install Bun

curl -fsSL https://bun.sh/install | bash
source ~/.bashrc

6. Create an empty folder in your home directory, ex. mkdir khofly.

7. cd khofly and type git clone https://github.com/cufta22/khofly.git .

7.1. Pick a branch, by default it will be on master but if you want more frequent updates git fetch origin staging and git checkout -b staging origin/staging

8. Build and run web client

cd web

# First create the .env.local file from example file
cp .env.example .env.local

# Edit the values per provided comments
nano .env.local

# Then we can install dependencies and build
pnpm install
pnpm run build

9. Create the ecosystem.config file for pm2

# Create the config
touch ecosystem.config.cjs

# Paste the base config from below, edit whatever you want
nano ecosystem.config.cjs

# Start the web client with pm2
pm2 start
module.exports = {
  apps : [{
    name: 'web',
    script: 'npm',
    args: 'run start',
    env: {
        PORT: 3000
    }
  }]
};

10. Create Nginx config for web, don't forget to update the server_name to your domain name.

cd /etc/nginx/sites-available/

# Create the config for the web client
touch web

# Paste the base config from below, edit whatever you want
nano web

# Link that file to /sites-enabled
ln -s /etc/nginx/sites-available/web /etc/nginx/sites-enabled/
server {
    server_name example.com;

    root /root/web;

    location / {
        # Proxy to pm2 server on 3000 for web

        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    listen 80;
}

11. Add SSL certificate for your domain certbot --nginx

12. sudo systemctl reload nginx

Updating

To update the web client, API and PV run ./scripts/update.sh. This will fetch the latest code and rebuild everything.

Make sure it is executable chmod +x ./scripts/update.sh.

Read more