# Deployment

> Choosing a host, your app's production keys, updating your app, giving it its own domain, and running your own server.

Your app runs on separate servers, not on Ghost's (see [How apps work](./how-apps-work.md)). While you build, that's your own computer. To keep your app working when your computer is off, put it on a host.

## Choosing a host

Any host that serves web pages over `https` and runs a little code of yours works. The code answers Ghost's challenge, which checks the app is yours (see [App identity](./app-identity.md#the-challenge)). A few that suit apps well:

| Host | Good for |
| --- | --- |
| **Cloudflare Workers** | Pages and small servers, free to start. Ghost's examples use it. |
| **Vercel**, **Netlify** | Pages and small servers, especially if you already use them for other sites. |
| **Fly.io**, **Render**, **Railway** | Full servers in any language, for apps that keep their own data or do work in the background. |

## Your app's production keys

Your deployed app signs its manifest with its own keys, separate from the development keys on your computer (see [Signing](./manifest.md#signing)). Create them once, in your app's folder:

```bash
pnpm exec ghost-app keys --production
```

This creates `.ghost-app/production/identity.json` and `backend.json`. Back up both files somewhere safe outside your app's folder, such as a password manager, and never commit them or paste their contents into a chat, an issue, or a log. The backend key only goes into your host's secret prompt, or straight into the host's command. Sites remember the identity key they installed your app with (see [Your app's keys](./security.md#your-apps-keys)).

## Cloudflare Workers

> Deploy my Ghost app to Cloudflare Workers by following <https://tryghost.github.io/Apps/deployment.md>, and give me the install link for its new URL.

The first time, Cloudflare asks you to sign in, or to create a free account. You get back your app's URL and an install link for it.

To deploy Ghost's examples manually, from your app's folder:

1. Sign in to Cloudflare, once: `npx wrangler login`
2. Create the production keys, once: `pnpm run production:keys`. Back up both files in `.ghost-app/production/` somewhere safe.
3. Save your app's address in `.env.production`, once: `GHOST_APP_URL=https://your-app.your-subdomain.workers.dev`. `your-app` is the `name` in `wrangler.jsonc`, and your account's `workers.dev` subdomain is under **Workers & Pages** in Cloudflare's dashboard, where a new account picks one. The address isn't secret, so commit the file.
4. Store the backend key as the Worker's `GHOST_APP_BACKEND_KEY` secret, once: `pnpm run production:secret`. It pipes the key from `.ghost-app/production/backend.json` straight to `wrangler secret put`, so it never shows on screen, and stops first if the key is missing. Alternatively, run `pnpm exec wrangler secret put GHOST_APP_BACKEND_KEY` and paste the file's contents into its secret prompt. Secrets stay with the Worker across deploys.
5. Deploy it: `pnpm run deploy`. The build signs the manifest for `GHOST_APP_URL`, and `wrangler deploy` puts it live. Without `GHOST_APP_URL`, the build warns and has no manifest, which takes the app down on every site, so keep it in `.env.production`.
6. Install it from `https://yoursite.com/ghost/#/apps/install?manifest=https://your-app.your-subdomain.workers.dev/ghost-app.json`.

## If Ghost refuses it

Installing is the check: Ghost fetches your app's manifest and checks that it's signed, the address it's signed for, the signature, and your server's answer to the challenge. If any of those fail, Ghost Admin says why. [Troubleshooting](./troubleshooting.md#ghost-cant-confirm-the-app-comes-from-you) says how to fix each one.

## From your computer to a host

The app on your computer and the deployed app have different identity keys, so they're different apps to Ghost (see [App identity](./app-identity.md#development-and-production-keys)). To move a site to the deployed app, uninstall the one from your computer in Ghost Admin, then install from the deployed app's link. Approvals and history start fresh with the new installation.

## Other hosts

> Deploy my Ghost app to Vercel by following <https://tryghost.github.io/Apps/deployment.md>. Check it meets the host requirements, and give me the install link for its new URL.

Name the host you'd like to use. Ghost's examples use Cloudflare Workers, so they need small changes for other hosts. Whatever you use, the host needs to:

- Serve your pages over `https`.
- Serve your app's signed manifest at a fixed URL, signed for that URL. With Vite, set `GHOST_APP_URL` to your app's address, such as `https://your-app.example.com`, in `.env.production`. Otherwise, sign it with `pnpm exec ghost-app sign --production --url <manifest URL> --out <file>`. Sign it on your computer or in a CI job (see [Updating it](#updating-it)), never where your app's server runs.
- Answer `POST /.well-known/ghost-app/challenge` with `handleChallenge()` from `@tryghost/app-sdk/backend`, with the private backend key as `GHOST_APP_BACKEND_KEY` in the host's secret settings. Pipe it straight in, such as `pnpm exec ghost-app backend-key --production | vercel env add GHOST_APP_BACKEND_KEY production`, so it never shows on screen. `handleChallenge()` runs anywhere with the web's standard `Request` and `Response`, such as Vercel, Netlify, Deno, or Node.
- Load every screen of your app from its own link, since Ghost reopens your app on the screen you were on.
- Let your page be embedded in an iframe on another site. Some hosts and frameworks block this by default.

A site you host yourself can skip the challenge for an app it trusts, with `apps.trustedOrigins` in Ghost's config (see [The challenge](./app-identity.md#the-challenge)). Every other site needs the answer.

## Updating it

Deploy the app again whenever you change it (with Cloudflare, run `pnpm run deploy` again). Ghost picks up the new version the next time someone opens the app. Small changes apply right away. Bigger ones, like a new name, wait for approval in Ghost (see [App lifecycle](./lifecycle.md#updates)).

To deploy each time you push to GitHub (see [Getting started](./getting-started.md)), sign the manifest where your app's server can't read the identity key: a CI job such as GitHub Actions, or the build secrets of Cloudflare's Workers Builds, which stay out of the Worker. Give the job two secrets: `GHOST_APP_IDENTITY_KEY`, the contents of `identity.json`, and `GHOST_APP_BACKEND_KEY`, the backend key's public half, which `pnpm exec ghost-app backend-key --production --public` prints. Signing needs nothing more, so the private backend key lives only in your server's secret settings. Never put the identity key in the variables your app's server runs with, such as a Vercel or Netlify project's environment variables, which their functions read too.

If you move your deployed app to a new URL, deploy it signed for the new URL and open the install link for it. Ghost asks you to approve the move, and it stays the same app, with its history, as long as it keeps the same identity key.

## Replacing or losing keys

[Losing or leaking a key](./app-identity.md#losing-or-leaking-a-key) explains what each case means for the sites that installed your app. The steps:

- **The backend key leaked:** Delete `.ghost-app/production/backend.json`, create a new one with `pnpm exec ghost-app keys --production`, which keeps the identity key, and back it up. Store it as the server's secret (`pnpm run production:secret` in Ghost's examples), update CI's public `GHOST_APP_BACKEND_KEY` if you have one, and deploy straight away. Between the new secret and the deploy, your server answers with the new key while the live manifest still names the old one, so Ghost can't confirm your app on sites that open it. The deploy closes that window.
- **The identity key leaked:** Delete `.ghost-app/production/`, both keys, create new ones with `pnpm exec ghost-app keys --production`, back them up, store the new backend key as the server's secret, update CI's `GHOST_APP_IDENTITY_KEY` and public `GHOST_APP_BACKEND_KEY`, and deploy. Then ask every site to uninstall your app and install it again from its link.
- **The identity key got lost:** Put your backup of `.ghost-app/production/` back, and carry on. Without a backup, it's the same as a leak: New keys, and every site installs your app again.

## Give your app its own domain

Put your app on a domain or subdomain that serves nothing else, such as `calendar.example.com`, or the `your-app.your-subdomain.workers.dev` subdomain Cloudflare gives you. Keep it away from domains that also serve something else, such as `example.com/calendar` next to your personal website, a forum, or a folder of files people upload.

That's because Ghost treats every page on your app's domain as your app. Any of them that opens inside Ghost can read and change your posts, pages, and tags, as whoever is using the app. If a page someone else wrote or uploaded lives on the same domain, it gets that access too.

The same goes for code you add to your app's page from other services, such as a chat widget or an analytics script. It runs with the same access as your app, so only add services you trust.

More in [Security](./security.md).

## Apps with their own server

An app with its own server can use any language or service you like, as long as it answers Ghost's challenge and the page Ghost shows meets the points in [Other hosts](#other-hosts).

### Calling Ghost from your server

Your app's page talks to Ghost through Ghost Admin, as the person using it, and needs no API keys. Do the work that calls Ghost in your page wherever you can.

Your server will call Ghost with a token of its own, carrying every scope the site approved for your app, and nothing more (see [Where your app uses its scopes](./access.md#where-your-app-uses-its-scopes)). These tokens are coming. Until they arrive, plan work that runs with nobody present, such as a scheduled task, around them, and declare the scopes it will need.

### Who's calling your server

Ghost doesn't verify which site or person a request to your server comes from. The site's address and the person's ID and role your page gets aren't proof. Anyone can send the same requests as your page, so check what your server does with them before it acts.

### Signing people in

Browsers block or partition third-party cookies, and inside Ghost your app's cookies count as third-party. If your server signs people in with a cookie, they can look signed out inside Ghost, in Safari especially. Ghost doesn't provide sign-in for your service yet. See [Sign people in without cookies](./adapt-an-existing-project.md#sign-people-in-without-cookies).
