Deploy on your own server

🇮🇩 Bahasa Indonesia

For a VPS (Ubuntu 24.04, 2 GB RAM is enough to start) instead of Replit. You get: PostgreSQL on the same machine, the API as a systemd service, and Caddy serving the web app with automatic HTTPS. About an hour.

Before you start: a domain pointing to the server (A record), and the Clerk application from 01 Quick tutorial steps 3 and 8 (production instance on this domain).

Uploads (course files, MP4 videos) use Replit App Storage and answer “not available” on your own server. Use YouTube links and resource links, or swap the storage code for S3-compatible storage (see 05).

1. Install the tools

sudo apt update && sudo apt install -y git postgresql caddy
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash - && sudo apt install -y nodejs
sudo corepack enable && corepack prepare pnpm@latest --activate
sudo useradd --system --create-home --shell /bin/bash courses

2. Database

sudo -u postgres psql -c "CREATE USER courses WITH PASSWORD 'choose-a-long-password';"
sudo -u postgres psql -c "CREATE DATABASE courses OWNER courses;"

DATABASE_URL=postgresql://courses:choose-a-long-password@localhost:5432/courses

3. Code and settings

sudo -iu courses
git clone https://github.com/<you>/<your-repo>.git app && cd app
cp .env.example .env && chmod 600 .env
nano .env

Fill in at least:

DATABASE_URL=postgresql://courses:…@localhost:5432/courses
CLERK_SECRET_KEY=sk_live_…
CLERK_PUBLISHABLE_KEY=pk_live_…
VITE_CLERK_PUBLISHABLE_KEY=pk_live_…
VITE_CLERK_PROXY_URL=https://belajar.example.id/api/__clerk
PLATFORM_ADMIN_EMAILS=you@example.id
LEARNING_CONTENT_ADMIN_EMAILS=you@example.id
LEARNING_PASS_PUBLIC_URL=https://belajar.example.id

…plus any optional integration (05).

4. Build

pnpm install --frozen-lockfile
pnpm db:push
pnpm db:seed                                   # optional example course
node scripts/with-env.mjs pnpm --filter @workspace/api-server run build
PORT=5173 BASE_PATH=/ node scripts/with-env.mjs pnpm --filter @workspace/learnspace run build
exit

The web app is now static files in artifacts/learnspace/dist/public; the API bundle is artifacts/api-server/dist/index.mjs. (VITE_* values are baked into the web build: rebuild after changing them.)

5. Run the API with systemd

/etc/systemd/system/courses-api.service:

[Unit]
Description=Course platform API
After=network.target postgresql.service

[Service]
User=courses
WorkingDirectory=/home/courses/app
EnvironmentFile=/home/courses/app/.env
Environment=NODE_ENV=production PORT=8080
ExecStart=/usr/bin/node --enable-source-maps artifacts/api-server/dist/index.mjs
Restart=always

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable --now courses-api
curl -s localhost:8080/api/config/features        # {"payments":false,...}

6. Serve everything with Caddy

/etc/caddy/Caddyfile:

belajar.example.id {
	encode zstd gzip

	handle /api/* {
		reverse_proxy localhost:8080
	}

	handle {
		root * /home/courses/app/artifacts/learnspace/dist/public
		try_files {path} /index.html
		file_server
	}
}
sudo chmod o+x /home/courses /home/courses/app      # let Caddy read the static files
sudo systemctl reload caddy

Caddy gets the HTTPS certificate automatically and passes X-Forwarded-Host/-Proto, which the Clerk proxy uses.

7. Updates and backups

sudo -iu courses
cd app && git pull && pnpm install --frozen-lockfile && pnpm db:push
node scripts/with-env.mjs pnpm --filter @workspace/api-server run build
PORT=5173 BASE_PATH=/ node scripts/with-env.mjs pnpm --filter @workspace/learnspace run build
exit
sudo systemctl restart courses-api

Nightly database backup (as courses, crontab -e):

30 2 * * * pg_dump "postgresql://courses:…@localhost:5432/courses" | gzip > /home/courses/backup-$(date +\%F).sql.gz && find /home/courses -name 'backup-*.sql.gz' -mtime +14 -delete

Copy the backups off the server (rsync, object storage) — a backup on the same disk doesn’t survive a lost server.

Other hosts

The same two pieces work anywhere: a static site (artifacts/learnspace/dist/public, with every unknown path rewritten to /index.html) and a Node 24 process (artifacts/api-server/dist/index.mjs, NODE_ENV=production) reachable under /api on the same domain, plus PostgreSQL. Keep the API always on: it runs the background jobs.