Skip to content

How to Deploy GymFlow on an Ubuntu VPS

  • by

This guide explains how to deploy GymFlow on an Ubuntu 22.04 VPS from providers such as DigitalOcean, Linode, Vultr, Hetzner, and other cloud VPS platforms.

Prerequisites

Before installing GymFlow, you need:

  • Ubuntu 22.04 LTS
  • At least 2 vCPUs
  • At least 2 GB RAM
  • 4 GB RAM recommended for production
  • Root or sudo SSH access
  • A domain name

Step 1 — Create a Deploy User

Connect to the server:

ssh root@your-vps-ip

Create a dedicated deployment user:

adduser deploy
usermod -aG sudo deploy

Copy SSH keys:

rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy

Switch to the deployment user:

su - deploy

Step 2 — Install System Dependencies

Update Ubuntu:

sudo apt update && sudo apt upgrade -y

Install the required packages:

sudo apt install -y git curl build-essential nginx ufw

Configure the firewall:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable

Step 3 — Install Node.js for GymFlow

Install Node.js 20:

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs

Install npm 11:

sudo npm install -g npm@11

Verify:

node -v
npm -v

Step 4 — Install PostgreSQL and Redis

Install PostgreSQL and Redis:

sudo apt install -y postgresql redis-server

Enable both services:

sudo systemctl enable postgresql redis-server

Create the GymFlow PostgreSQL user:

sudo -u postgres createuser --interactive --pwprompt gymflow

Create the production database:

sudo -u postgres createdb -O gymflow gymflow_production

Verify Redis:

redis-cli ping

Step 5 — Download GymFlow

Navigate to the deployment user’s home directory:

cd /home/deploy

Clone GymFlow:

git clone https://github.com/your-org/gymflow.git

Enter the application directory:

cd gymflow

Step 6 — Configure GymFlow

Create the environment file:

cp .env.example .env

Edit the configuration:

nano .env

Add the required GymFlow production settings:

DATABASE_URL="postgresql://gymflow:your_password@localhost:5432/gymflow_production"
REDIS_URL="redis://localhost:6379"
JWT_SECRET="your-long-random-secret"
NEXT_PUBLIC_API_URL="https://api.yourdomain.com"

STRIPE_SECRET_KEY="sk_live_..."
SENDGRID_API_KEY="SG...."

Switch the GymFlow database provider:

npm run db:provider:postgresql

Step 7 — Install and Build GymFlow

Install dependencies:

npm install

Build the application:

npm run build

Run database migrations:

npm run db:migrate

Seed the database:

npm run db:seed

Step 8 — Configure PM2 for GymFlow

Install PM2:

sudo npm install -g pm2

Create:

ecosystem.config.js

Add:

module.exports = {
  apps: [
    {
      name: 'gymflow-api',
      script: 'npm',
      args: 'run start --workspace=apps/api',
      env: {
        NODE_ENV: 'production'
      }
    },
    {
      name: 'gymflow-web',
      script: 'npm',
      args: 'run start --workspace=apps/web',
      env: {
        NODE_ENV: 'production'
      }
    }
  ]
};

Start GymFlow:

pm2 start ecosystem.config.js

Configure automatic startup:

pm2 startup systemd

Save the processes:

pm2 save

Step 9 — Configure Nginx

Create the Nginx configuration:

sudo nano /etc/nginx/sites-available/gymflow

Add:

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://localhost:3000;
    }
}

server {
    listen 80;
    server_name api.yourdomain.com;

    location / {
        proxy_pass http://localhost:4000;
    }
}

Enable the GymFlow site:

sudo ln -s /etc/nginx/sites-available/gymflow /etc/nginx/sites-enabled/

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Enable HTTPS:

sudo certbot --nginx -d yourdomain.com -d api.yourdomain.com

Reload Nginx:

sudo systemctl reload nginx

Step 10 — Update GymFlow

Navigate to the GymFlow project:

cd /home/deploy/gymflow

Pull the latest code:

git pull origin main

Install updated dependencies:

npm install

Rebuild GymFlow:

npm run build

Run any new migrations:

npm run db:migrate

Restart the application:

pm2 restart all