/ Docs

Installation guide

Requirements:

  • a VPS
  • Fully qualified domain name

OPTION 1. Install script ( Recommended )

This part is covered in docs/self-host-khofly VPS section, the ./scripts/install.sh script installs and runs both the web client and the API. If you've already run that script you probably don't need this page.

OPTION 2. Manual installation

Follow these steps only if you've manually installed Khofly web client.

1. Install dependencies

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

2. Install pm2

npm install pm2 -g
source ~/.bashrc

3. Install Bun

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

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

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

5.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

6. Build and run API

cd pv

# 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
bun install

7. Create the ecosystem.config file for pm2

# Create the config
touch ecosystem.config.js

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

# Start the API with pm2
pm2 start
module.exports = {
  apps : [{
    name: 'pv',
    script: 'bun',
    args: 'run start',
  }]
};

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

cd /etc/nginx/sites-available/

# Create the config for the API
touch pv

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

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

    root /root/pv;

    location / {
        # Proxy to pm2 server on 4001 for pv

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


    listen 80;
}

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

10. sudo systemctl reload nginx

Updating

To update the PV run ./scripts/redeploy-pv.sh pv, make sure to replace "pv" with pm2 instance name for your PV.

To get a list of all pm2 instances run pm2 ls

Read more