Put your app on the internet
What you will do
You will take the notes app from your own computer to the internet: create the app on the real server, register the web address of your live page, publish your collections there, upload the page to a web host, and check that users can sign in from the live page.
A few words used on this page:
- An app is the web app you build. A user is the person who uses it; on the real server, users have their own accounts and their own private databases.
- An origin is the start of a web address:
https, the host and, if it is not the usual one, the port, such ashttps://notes.example.com. The server lets an app sign users in only from the origins registered for it. - A developer token is a secret key, starting with
pbd_, that lets the CLI (thenpx phibaccommand-line tool) create and change your apps and schemas on one server. It can never read or change anyone's data. - A collection is one kind of data, such as notes, described by its schema. A collection published on your local server does not exist on the real server until you publish it there.
- Consent is the user's approval: the first time a user signs in to your app, the server asks them whether your app may store data for them.
Before you start
You need:
- The notes app from Build your first app, working on your own computer.
- A web host for the page. The page is only static files (HTML and JavaScript), so a host that serves static files over
httpsis enough. It must serve them at the root of their own address, such ashttps://notes.example.com/. This guide uses that address; use yours instead. - The real server's address. This server is
https://phibac.com. If you publish to another server, use its address instead wherever this guide uses this one. - Collection names you own. On a shared server the first app to publish a name owns it, so names starting with
com.examplemay already be taken. If yours start withcom.example, rename them to a domain you control first, publish them locally (a new name is a new collection) and use the new names in your page.
This server has no plans or payments: every account can connect apps, save data and publish collections. If you run the server yourself, it must be reachable over https at the address set in its PB_BASE_URL, and it must be able to send email, so users can sign up. The deployment guide in the server's source code (deploy/README.md) explains both.
Run the commands for the real server in a terminal of their own (terminal 3), so that your terminals for local development keep using the local server.
Steps
1. Create an account and a developer token on the real server
Accounts, keys and apps on your local server do not exist on the real server. On your computer the CLI used the local server's own key (./.pb/developer-token); the real server needs a developer token that you create there.
- Open
https://phibac.com/signup, type your email address and press Send me a link. Open the link from the email in the same browser, press Confirm and continue, then choose Create a passkey or Set a password. - Open
https://phibac.com/account/developer, type a name for the token and press Create token. Copy it: it is shown only once.
In terminal 3, in your notes folder, point the CLI at the real server and give it the new token:
export PB_BASE_URL=https://phibac.com
export PB_TOKEN=pbd_...
2. Create the app and register its origin
npx phibac init cannot do this here, because it writes pb.config.ts and will not overwrite the one you have. Create the app with the developer API instead, giving its name and the origin of your live page:
curl -X POST "$PB_BASE_URL/v1/apps" \
-H "Authorization: Bearer $PB_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "Notes", "origins": ["https://notes.example.com"]}'
The answer is the new app (your ID is different):
{"id":"app_01M7EF0XHSDKF5PM495J1TA5AF","name":"Notes","origins":["https://notes.example.com"],"status":"active"}
Keep the id: it is your app's ID on the real server. name is what users see when they are asked for consent. The origin rules:
- Use
https. Plainhttpis accepted only forlocalhost,127.0.0.1and[::1]. - Give the origin only: no path, such as
/app, and no trailing parts.https://www.notes.example.comandhttps://notes.example.comare different origins; register each one your page is served from. - An app can have at most 20 origins.
To change the origins later, send the whole new list with PATCH, as Sign users in shows: it replaces the old list. Developer API and agent tools describes both routes. An AI coding tool connected to the server can do both with its create_app and update_app_origins tools.
3. Let pb.config.ts name either app
Your app now has one ID on the local server and another on the real server, and pb.config.ts names the app that npx phibac deploy publishes for. Let it read the real server's app ID from an environment variable, PB_APP, and keep the local one as the default: add the declare const process line and change the app line, and keep your collections as they are. After Change your schema safely, the file is (keep your own local app ID):
import { defineApp, collection, string, boolean, fileRef } from "phibac";
// pb.config.ts runs in Node.js, where process.env holds your environment variables.
declare const process: { env: Record<string, string | undefined> };
export default defineApp({
// The app on the real server when PB_APP is set, otherwise the one on the local server.
app: process.env.PB_APP ?? "app_...",
collections: {
"com.example.notes.note": collection({
version: 2,
description: "A note written by the user",
fields: {
text: string({ description: "Note text", maxLength: 20000, required: true }),
starred: boolean({ description: "Whether the user starred the note", indexed: true }),
photo: fileRef({ description: "A photo attached to the note" }),
title: string({ description: "A short title for the note", maxLength: 200 }),
},
}),
},
});
The declare const process line only tells TypeScript about process.env; your editor may need it, and it changes nothing when the CLI reads the file. If you skipped that guide, your collection is still at version 1: make the same two changes to your file.
4. Publish your collections to the real server
The real server has none of your collections yet, and it takes major versions only in order, starting with 1. If your collection is at version 1, one command publishes it. In terminal 3, with the app ID from step 2:
PB_APP=app_... npx phibac deploy
Previewing 1 collection for app app_01M7EGKQX21JEARPKQM1EXM8MB on https://phibac.com
com.example.notes.note additive (will become version 1.0)
published com.example.notes.note version 1.0
Published 1 collection.
After Change your schema safely your collection is at version 2, and the same command refuses with invalid_request: collection "com.example.notes.note" is new, so its version must be 1 (got 2), publishing nothing. Publish version 1 first, as it was before the breaking change: save your current pb.config.ts under another name (for example cp pb.config.ts version-2.txt), replace pb.config.ts with your collections as they were at version 1, and run PB_APP=app_... npx phibac deploy, which prints the four lines above. After Change your schema safely, that is the file below; if you added fields in other guides before that one, add them to it too, as they were then:
import { defineApp, collection, string, boolean, fileRef } from "phibac";
// pb.config.ts runs in Node.js, where process.env holds your environment variables.
declare const process: { env: Record<string, string | undefined> };
export default defineApp({
// The app on the real server when PB_APP is set, otherwise the one on the local server.
app: process.env.PB_APP ?? "app_...",
collections: {
"com.example.notes.note": collection({
version: 1,
description: "A note written by the user",
fields: {
text: string({ description: "Note text", maxLength: 20000, required: true }),
pinned: boolean({ description: "Whether the note is pinned", indexed: true }),
photo: fileRef({ description: "A photo attached to the note" }),
title: string({ description: "A short title for the note", maxLength: 200 }),
},
}),
},
});
Then put your version 2 file back (cp version-2.txt pb.config.ts) and run PB_APP=app_... npx phibac deploy again. It prints additive (will become version 2.0) and published com.example.notes.note version 2.0.
Run PB_APP=app_... npx phibac deploy in terminal 3 after every change you publish locally, so both servers have the same major versions with the same fields (their minor numbers can differ, for example 1.2 locally and 1.0 on the real server). You do not need to run npx phibac generate for the real server: it reads the published schemas from the server for the collections and major versions in pb.config.ts, and both servers now publish the same fields for each of those major versions, so src/pb-types.ts comes out the same.
5. Choose the server and app in your page
Your page must use the real server and the real server's app ID when it runs on the live origin, and the local ones everywhere else. In src/main.ts (the file from Upload and show files, or the quickstart's), replace the two lines that set APP and BASE_URL with these, putting the real server's app ID in the first app_..., your local app ID in the second, and the real server's address in place of https://server.example.com (for this server, https://phibac.com):
// The live page uses the app on the real server; a page on any other origin uses the local server.
const LIVE = location.origin === "https://notes.example.com";
const APP = LIVE ? "app_..." : "app_...";
const BASE_URL = LIVE ? "https://server.example.com" : "http://localhost:8787";
The rest of the file stays as it is.
6. Build the page and upload it
In terminal 3, build the page:
npx vite build
Vite writes the finished page to the dist folder: index.html and an assets folder. Upload everything inside dist to your web host, so that https://notes.example.com/ serves dist/index.html. To look at the build before you upload it, run npx vite preview: it serves dist on http://localhost:4173, and since that is not the live origin, the page uses the local server.
7. Check sign-in from the live page
Open https://notes.example.com and press Sign in. The popup must come from the real server: its address starts with https://phibac.com. Sign in with your account on the real server (the passkey or password of your local account does not work there), then press Allow on the consent page. Add a note: it shows (synced) once the real server has it. In your account area on the real server, https://phibac.com/account/apps now lists Notes.
What you should see
PB_APP=app_... npx phibac deploypublishes each major version of your collection on the real server, starting with 1.0.- On the live page, Sign in opens a popup from the real server. The first time, it asks: "Notes (https://notes.example.com) will store data in your backend." After Allow, the popup closes and you can add notes.
- A user who has no account on the real server sees the real server's sign-in page in the popup, titled "Sign in to" and that server's name, with a Create an account link. After they type their email address, the popup says "Check your email". They open the link from the email in the same browser, usually in a new tab: there they confirm their address, create a passkey or set a password, and are asked to connect Notes. After Allow, that tab says "Connected" and that it lost its link to the app. Back on your page, they close the popup, which makes
connect()fail withsign_in_cancelled, and press Sign in again: this time the popup closes by itself and they are signed in. Show a message such as "Press Sign in again" whenconnect()fails withsign_in_cancelled. http://localhost:5173still uses your local server and its data.
Common problems
unauthorized: the developer token is invalid or revoked. The token was made on another server, such as your local one. Create one onhttps://phibac.com/account/developerand export it in terminal 3.not_foundsaying the app "does not exist".npx phibac deployused your local app ID on the real server, becausePB_APPwas not set. Run it asPB_APP=app_... npx phibac deploy.forbiddensaying the collection "is owned by another app". Someone already published that name on the real server. Rename your collection to a domain you control, publish it locally and on the real server, and use the new name in your page.invalid_requestsaying the collection "is new, so its version must be 1". Your local collection is at a later major version, but the real server has none yet. Publish version 1 first (thepb.config.tsyou had then), then each later major version in order, as in step 4.invalid_requestsaying the origin "must use https" or "is not a web origin". Register onlyhttps://and the host, with no path.- The popup says "The app asked to sign in from an address it has not registered." The live page's origin is not registered for the app on the real server, often because of
wwwor a different port. Add the exact origin withPATCH, keeping the others. - The popup says "This app is not registered." The page used the local app ID with the real server, or the other way round. Check the origin in the
LIVEline: it must match the address bar exactly. popup_blockedorsign_in_cancelledon the live page. The same causes as on your own computer: see Sign users in.
Next step
Your app is live. Check it against Common mistakes, the problems first apps run into most often, and keep Errors and how to fix them at hand for any error code your users meet.