# Self-hosting overview

> Run GoPayLocal on your own Cloudflare account and Postgres database. What you deploy, what you need, which Cloudflare plan, and the order of the setup steps.

Source: https://docs.gopaylocal.com/self-hosting/

The GoPayLocal server is open source. You can run the same code as the hosted service on your own Cloudflare account, with your own Postgres database.

A self-hosted install runs in self-hosted mode (`SELF_HOSTED="true"`). Every organization is unlimited, the "Powered by GoPayLocal" link on the banner is off, and billing is switched off. Every feature is included. [Differences from hosted](https://docs.gopaylocal.com/self-hosting/hosted-differences.md) lists the rest.

> **License:**
> The server (everything under `apps/`) is licensed AGPL-3.0-only. The SDKs and the banner script (`packages/`) are MIT. If you modify GoPayLocal and let other people use it, read [If you run your own copy of the service](https://github.com/RayLabsHQ/gopaylocal/blob/main/LICENSING.md#if-you-run-your-own-copy-of-the-service) in `LICENSING.md` before you launch. It says what the AGPL requires of you.

## What you deploy

| Part | Runs as | Needed? |
|---|---|---|
| API (`apps/api`) | A Cloudflare Worker with Hyperdrive, two KV namespaces, rate limiters and three cron triggers | Yes. It serves the banner, the SDK endpoints, the dashboard's API, sign-in and provider webhooks. |
| Dashboard (`apps/dashboard`) | A Cloudflare Worker that serves static files | Yes, to manage products, campaigns, integrations and your team. |
| Admin app (`apps/admin`) | A Cloudflare Worker that serves static files | Optional. Platform admin screens: overview, organizations, users, alerts and audit log. |
| Docs (`apps/docs`) | A Cloudflare Worker that serves static files | Optional. |
| Marketing site (`apps/web`) | Not deployed | No. It is the gopaylocal.com landing site. |
| Postgres | Your database provider | Yes. |

## Requirements

- **A Cloudflare account.** See [Cloudflare plan](#cloudflare-plan) below for Free versus Paid.
- **A domain with its DNS on Cloudflare** (recommended). You need one to serve the Workers on your own hostnames: a Custom Domain requires an active Cloudflare zone ([Custom Domains](https://developers.cloudflare.com/workers/configuration/routing/custom-domains/)). See [Domains and sign-in cookies](#domains-and-sign-in-cookies).
- **Postgres 15 or newer**, reachable by Cloudflare Hyperdrive over TLS. The schema needs 15 (it uses a `NULLS NOT DISTINCT` unique constraint); CI tests on 18. See [Database and migrations](https://docs.gopaylocal.com/self-hosting/database.md).
- **A Google OAuth client or a GitHub OAuth app**, or both. Public email sign-up is disabled, so OAuth is how people create accounts. See [OAuth setup](https://docs.gopaylocal.com/self-hosting/oauth.md).
- **On your computer:** Git; Node.js at a version allowed by the `engines` field of the root `package.json` (22.23.4 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 and later); and pnpm at the version pinned in its `packageManager` field. Running `corepack enable` once makes Corepack fetch and use exactly that version (on Node 26, install it first with `npm install -g corepack`).

## Cloudflare plan

Figures from Cloudflare's documentation, checked November 2026. Follow the links for current values.

| | Workers Free | Workers Paid |
|---|---|---|
| Price | $0 | Minimum $5 per month per account ([pricing](https://developers.cloudflare.com/workers/platform/pricing/)) |
| CPU time per HTTP request | 10 ms | 30 s by default, up to 5 min ([limits](https://developers.cloudflare.com/workers/platform/limits/#cpu-time)) |
| CPU time per cron run | 10 ms | 15 min for schedules that run hourly or less often; 30 s for more frequent ones ([limits](https://developers.cloudflare.com/workers/platform/limits/)) |
| Requests per day | 100,000 ([limits](https://developers.cloudflare.com/workers/platform/limits/)) | Billed by usage ([pricing](https://developers.cloudflare.com/workers/platform/pricing/)) |
| Hyperdrive | Included: 100,000 queries per day, about 20 database connections per configuration | Included: unlimited queries, about 100 connections ([pricing](https://developers.cloudflare.com/hyperdrive/platform/pricing/), [limits](https://developers.cloudflare.com/hyperdrive/platform/limits/)) |
| KV | 100,000 reads and 1,000 writes per day, 1 GB stored ([limits](https://developers.cloudflare.com/kv/platform/limits/)) | Billed by usage |
| Cron triggers per account | 5 (GoPayLocal uses 3) | 250 |
| Static files (dashboard, admin, docs) | Free and unlimited | Free and unlimited |

**What needs Workers Paid:** the daily VPN data refresh. The `30 9 * * *` cron rebuilds the VPN, datacenter and Tor IP dataset. That took 0.2 to 0.3 seconds of CPU in our Node measurements, far more than the Free plan's 10 ms per cron run. On Free, the run stops before it writes anything, and you build and upload the data from your computer instead: see [VPN detection: Workers Free](https://docs.gopaylocal.com/guides/vpn-detection.md#workers-free-build-locally-and-upload). Until the data is loaded, VPN detection only checks the visitor's network against a built-in list of datacenter and VPN networks. The `40 */6 * * *` cron refreshes the exchange rates used for local prices. Its CPU use has not been measured on Workers Free. If it has not run, banners still work and show exact prices in your product's currency, with no converted estimate.

Nothing else in the configuration is documented by Cloudflare as Paid-only. Hyperdrive "is included in both the Free and Paid Workers plans". Cloudflare's [rate limiting binding](https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/) page does not say which plans include it.

> **Note:**
> We have not measured GoPayLocal against the Free plan's 10 ms of CPU per request and per cron run. Some requests do real work: decrypting a stored payment-provider token (needed when a coupon is created) runs 100,000 PBKDF2 iterations, and the `*/10 * * * *` cron recomputes usage for every organization. Each pageview that shows the banner also costs several Worker requests against the Free plan's 100,000 a day. Use Workers Paid for anything beyond a trial.

## Domains and sign-in cookies

Put the API, the dashboard and the admin app on hostnames under one domain, for example `api.example.com`, `app.example.com` and `admin.example.com`.

Sign-in uses a session cookie that the API sets with `SameSite=Lax` (Better Auth's default). Browsers send that cookie with the dashboard's requests to the API only when both are on the same site, meaning the same registrable domain. Hostnames on two different domains do not work.

The `workers.dev` hostnames of one Cloudflare account (`<worker>.<account>.workers.dev`) also count as one site, because `workers.dev` is on the [Public Suffix List](https://publicsuffix.org/list/). The hosted service uses custom domains, and a `workers.dev`-only setup has not been tested.

## Setup, in order

1. [Database and migrations](https://docs.gopaylocal.com/self-hosting/database.md): create the database and apply the schema.
2. [Cloudflare setup](https://docs.gopaylocal.com/self-hosting/cloudflare.md): create the Cloudflare resources, write `wrangler.toml`, set secrets, deploy the API and the dashboard.
3. [OAuth setup](https://docs.gopaylocal.com/self-hosting/oauth.md): create the Google or GitHub OAuth app that people sign in with.
4. [First admin user](https://docs.gopaylocal.com/self-hosting/first-admin.md): sign in and give yourself the admin role.

Reference pages:

- [Configuration reference](https://docs.gopaylocal.com/self-hosting/configuration.md): every variable, secret and binding.
- [Upgrading](https://docs.gopaylocal.com/self-hosting/upgrading.md): pulling new versions and running new migrations.
- [Differences from hosted](https://docs.gopaylocal.com/self-hosting/hosted-differences.md).

The source of truth for the API's configuration is `apps/api/wrangler.example.toml` in the repository. Every binding, variable and secret in it has a comment saying what it is for and whether it is required.
