Vite + Supabase + PM2 + Nginx Deploy Script
This script sets up a Hetzner server to host a Vite app from GitHub using PM2, Nginx, Certbot SSL, and Supabase environment variables.
Instructions
- Edit the
DOMAIN,REPO,EMAIL, and Supabase variables at the top. - Upload the script to your server (e.g.,
/root/deploy.sh). - Make it executable:
chmod +x deploy.sh. - Run it:
./deploy.sh.
Deploy Script
#!/usr/bin/env bash
set -euo pipefail
######################
# EDIT THESE FIRST #
######################
DOMAIN="espressocafebar.eu"
REPO="https://github.com/youruser/your-vite-repo.git"
EMAIL="your-email@example.com"
# --- Supabase / ENV settings ---
SUPABASE_URL="https://dagnscrjrktrrspyamwu.supabase.co"
SUPABASE_ANON_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFz..."
WEBHOOK_AUTH_TOKEN="hWrqAUlCk52lXEDD9OyjS4cuU7XWU9"
######################
# 1) System update & prerequisites
apt update && apt upgrade -y
apt install -y curl git nginx certbot python3-certbot-nginx
# Install Node.js 20.x
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
# 2) Clone & build prep
TARGET="/var/www/$DOMAIN"
rm -rf "$TARGET"
mkdir -p "$TARGET"
git clone "$REPO" "$TARGET"
cd "$TARGET"
# 2a) Create .env for Vite/Supabase
cat > .env </dev/null || true
pm2 serve "$TARGET/dist" 3000 --name "$DOMAIN" --spa
pm2 save
pm2 startup systemd --silent
# 4) Nginx config
CONF="/etc/nginx/sites-available/$DOMAIN"
cat > "$CONF" <