Skip to content

A practical guide for hosting self-managed TypeScript apps on a VPS, with tools like Coolify, Postgres, PowerSync, and Supertokens. Learn to set up services locally, configure Hetzner VPS, secure with Cloudflare, and deploy seamlessly. Ideal for replicating localhost setups to staging/production.

Notifications You must be signed in to change notification settings

guillempuche/selfhost_fullstack_in_vps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VPS

Empower your software hosting it on a VPS (Virtual Private Server). Cheaper and portable.

If you want to replicate your localhost to staging/production, you can use this guide.

Self-hosted TypeScript apps I'm using:

Self-hosted services I'm using:

  • [VPS] Hetzner
  • [Git] GitHub
  • [Deployment] Coolify
  • [Database] Postgres
  • [Local-Cloud Sync] PowerSync
  • [Auth] Supertokens

Other services:

  • [Reverse Proxy] Traefik (configured in Coolify)
  • [DNS, TLS, Protection] Cloudflare
  • [Email] Docker Inbucket for local development (not VPS)
  • [Postgres Migration] Flyway

For Postgres migration, I'm using Flyway.

Content Table

  1. Fork my services folder to your repository.
  2. Copy the .env.example file to .env and update the variables.
  3. From each service directory, run docker compose up to start the services.
  1. Create VPS on Hetzner (cheaper than AWS; link 2. link 2). Debian.
  2. Connect to your Hetzner VPS with SSH. Guide https://docs.hetzner.com/cloud/servers/getting-started/connecting-to-the-server/
  3. Update and upgrade Debian packages.
sudo apt update && sudo apt upgrade -y

[!CAUTION] Work in progress

  1. Enable TLS Strict mode on Cloudflare https://developers.cloudflare.com/ssl/origin-configuration/ssl-modes/full-strict/
  2. Create a Cloudflare Origin CA https://developers.cloudflare.com/ssl/origin-configuration/origin-ca/
  3. Setup a DNS record for your domain pointing to your VPS.
  4. Obtain API Token from Cloudflare and update Traefik .env

Cloudflare DNS

Use cloud or self-hosted. I'm using the cloud (only $5/month).

  1. Create a Coolify account.

  2. Create a new server in an Staging or Production environment. My case is Staging.

    Coolify server
  3. Create a SSH key automatically with the "Generate new Ed25519 SSH key" function.

    To allow Coolify to connect to your VPS, you need to create a SSH key. I prefer to use a different one than my laptop (in step #1).

    Coolify ssh step 1 Coolify ssh step 2
  4. I'm using the root user automatically created by the VPS. Note that this is not recommended for production. Coolify has a beta feature to allow other users.

  5. Create a source with GitHub Apps to connect Coolify to your repository.

    Coolify sources
  1. Create a new resource on Coolify via the source you created in the previous step (GitHub Apps).

    Coolify resources step 1
  2. Select (Docker Compose instead of Nixpacks). Remember to write the branch you want to deploy.

    Coolify resources step 2
  3. Check .env.example of this repo Environment Variables of the resource --> Production. Add the missing variables to Coolify.

  4. Create Docker network (found in docker-compose.yaml files) in the VPS using SSH terminal. This is to allow the services to communicate with each other.

    docker network create backend_network
  5. Deploy the service.

  6. Do this for each service (PowerSync, Supertokens, Postgres).

Todo

  • Add Traefik for reverse proxy to Coolify.

About

A practical guide for hosting self-managed TypeScript apps on a VPS, with tools like Coolify, Postgres, PowerSync, and Supertokens. Learn to set up services locally, configure Hetzner VPS, secure with Cloudflare, and deploy seamlessly. Ideal for replicating localhost setups to staging/production.

Topics

Resources

Stars

Watchers

Forks