Develop on your own machine
What you will do
You will run a phibac server on your own computer with npx phibac dev, learn where it keeps its data, create a test account on it, see how the CLI gets in without a token, serve your page from the right web address, and start again with empty data when you want to.
A few words used on this page:
- An app is the web app you build. A user is the person who uses it; on your own computer, that is you, with a test account.
- A developer token is a secret key, starting with
pbd_, that lets the CLI (thenpx phibaccommand-line tool) create and change your apps and their schemas, the descriptions of their data. It can never read or change anyone's data. On the local server you do not need to make one: the server makes its own. - A passkey is how users sign in: a key kept on the device and unlocked with the device's screen lock, fingerprint or face. A user can also sign in with their email address and a password.
- An origin is the start of a web address:
httporhttps, the host and the port, such ashttp://localhost:5173. Each app lists the origins its pages may be served from.
Before you start
You need a project folder with the CLI installed, as in step 1 of Build your first app (npm install --save-dev phibac), Node.js 22 or newer, and a browser (one that supports passkeys, if you want to sign in with one).
The local server comes with the CLI: installing phibac also installs the server program built for your computer, and npx phibac dev runs it. There is one for macOS, Linux and Windows on x64, and for macOS and Linux on arm64.
Use your own server build
On another computer, or to run a server you built from its source code, build it with make build (this needs Go), which writes server/bin/pb-server, and tell the CLI where it is before you start it. It then runs that program instead of the one that came with it:
export PB_SERVER_BIN=/full/path/to/server/bin/pb-server
Steps
1. Start the local server
In your project folder, in a terminal of its own:
npx phibac dev
It prints this line, followed by the server's log:
Starting /full/path/to/server/bin/pb-server (PB_MODE=dev, data in ./.pb, http://localhost:8787). Press Ctrl-C to stop.
The local server always listens on http://localhost:8787; the port cannot be changed. It runs in development mode, with no limits on storage, requests or downloads. Warnings in the log that backups are off and that no alert email is set are expected. Press Ctrl-C to stop it. CLI reference describes npx phibac dev in full.
npx phibac dev always sets five of the server's environment variables itself: PB_MODE=dev, PB_LOCAL_DEV=1, PB_DATA_DIR=./.pb, PB_PORT=8787 and PB_BASE_URL=http://localhost:8787. Your own values for these five are ignored; for PB_BASE_URL, which you may have set to publish to another server, it says so and still uses http://localhost:8787. The server gets your other environment variables as they are.
PB_LOCAL_DEV=1 turns on what makes the local server easy to use: it makes its own developer key for the CLI (step 4), it shows on the page what an email would have said instead of sending it (step 3), and it accepts connections only from this computer, so nobody else on your network can reach it.
2. Know where your data is kept
The local server keeps everything in the folder ./.pb, inside the folder you started it from:
control.db: accounts, passkeys, password hashes, developer tokens, apps and published schemas.users/: one database per user, with their records.blobs/: the files your apps uploaded.secret: a random key the server made on first start, used to sign links and protect stored keys.developer-token: the local server's own developer key, which the CLI uses (step 4).
Start npx phibac dev from the same folder every time, or you get a different, empty ./.pb. The folder holds the secret, the key and your test data, and has no place in your repository: npx phibac dev adds a .pb/ line to the .gitignore file in the folder you start it from (and creates that file if there is none), and prints one line saying so. If it cannot change the file, it says so: then add .pb/ to .gitignore yourself.
3. Create a test account
- Open
http://localhost:8787/signup, type an email address and press Send me a link. Any address works, even a made-up one: the local server never sends email. - Instead of telling you to check your email, it goes straight to the next page. Press Confirm and continue.
- On the page "Choose how to sign in", press Create a passkey or Set a password.
If you created a passkey, your browser now keeps it for localhost: use the same browser to sign in to your apps. If you set a password, you can sign in from any browser. A browser you have not used before also asks for a code. Every page that would tell you to check your email (that code, a forgotten password, account recovery) shows, on the local server, a box with the latest email the server would have sent, who it went to and how long ago, with its links as buttons. Use the code or the button from there.
4. The CLI uses the local key
You do not need to create a developer token for the local server. Before it starts answering, the local server writes its own developer key to ./.pb/developer-token, and npx phibac init, deploy and native use that key by themselves whenever they talk to the local server. If the server is still starting, they wait a few seconds for it. Keep the key file where it is, and do not copy it, print it or paste it into a chat.
The CLI sends every command to the server in PB_BASE_URL, and to http://localhost:8787 when it is not set, so leave PB_BASE_URL unset while you work locally. Run the CLI from the same folder as npx phibac dev: that is where it looks for ./.pb/developer-token.
The apps the CLI creates belong to a built-in developer account of the local server, not to your test account, so they are not listed on your account's developer page. Nobody signs in to that account.
5. Serve your page from a registered origin
An app is created with the origin its page is served from, as in step 4 of Build your first app:
npx phibac init --name "Notes" --origin http://localhost:5173
Serve the page on exactly that origin, for example with npx vite --port 5173 --strictPort.
A page on an http://localhost origin that is not registered for your app can still sign in, but the server then asks the user to approve your app at every sign-in, naming the origin. Any program on a computer can serve a page from localhost, so the server never trusts an unregistered one by itself. 127.0.0.1 and [::1] are origins of their own, without this exception: register them if you use them. To add or change origins, see Sign users in.
6. Start again with empty data
To throw away everything on the local server and start fresh:
- Stop
npx phibac devwith Ctrl-C. - Delete the
./.pbfolder: runrm -rf ./.pbin the folder you started it from. - Start
npx phibac devagain. It makes a new, empty./.pb.
Everything is gone: your account, its passkey or password, the local key, apps, published schemas, records and files. The server makes a new key when it starts. Then set things up again:
- Create a new account (step 3).
- Your app no longer exists, and
npx phibac initwill not overwritepb.config.ts. Rename it (mv pb.config.ts old-config.ts), runnpx phibac initwith your app's name and origin, then copy your collections from the old file into the new one, keeping the new app ID. Delete the old file. - Run
npx phibac deployandnpx phibac generate, and put the new app ID in your page's code.
Your browser still offers the old passkey for localhost, but the server no longer knows it: signing in with it fails with "sign-in failed". Use the passkey you created for the new account, and remove the old one in your browser's or password manager's passkey settings. A page that was signed in before the reset shows unauthorized at its next request; it signs in again from a click.
What you should see
npx phibac devprints itsStarting …line, andhttp://localhost:8787/healthzanswers{"ok":true,…}.- A
./.pbfolder appears in the folder you started it from, withcontrol.db,usersandblobsin it once you have signed up and saved data. - A
./.pb/developer-tokenfile appears as soon as the server has started, and.gitignorehas a.pb/line. - After a reset,
http://localhost:8787/accountshows the sign-in page.
Common problems
npx phibac devsays the local server package is not installed. The packages were installed with--omit=optional(or--no-optional), which skips the server that comes with the CLI. Runnpm install --save-dev phibacagain without that flag.npx phibac devsays there is no server package for this computer. Build one yourself, as in Use your own server build.npx phibac devsays the server package's version is not the CLI's. The two were installed at different times. Runnpm install --save-dev phibacagain so they match.npx phibac devstops with "address already in use". Another program, oftennpx phibac devstarted from another folder, is using port 8787. Stop it and start again.npx phibac devstops with "another server or a restore is using ./.pb". A local server is already running from this folder. Use that one, or stop it first.- Your account, apps or data are gone. You started
npx phibac devfrom another folder, so it uses another./.pb. Start it from the folder you used before. - The CLI says "No local developer key found". The local server is not running. Start
npx phibac devin the folder you run the CLI from, then run the command again. - The CLI says a local server "was started in another folder". Run the command in the folder you started
npx phibac devfrom (the one with./.pb), or stop that server and startnpx phibac devin this folder. unauthorized: the developer token is invalid or revoked. The key in./.pb/developer-tokenno longer fits the server, for example after files inside./.pbwere deleted by hand. Start again with empty data (step 6). If you setPB_TOKENyourself, see Use your own developer token.- The CLI says the app was made by another account on this server. The app in
pb.config.tswas created with your own token, before the local server had its own key. SetPB_TOKENto a token of the account that made it, as in Use your own developer token, or start again with empty data (step 6). - A link from the box on the page does not work. Each link works once, and the box shows only the latest email the server would have sent: do the step again to get a new one.
- The user is asked to approve your app at every sign-in. The page runs on an
http://localhostorigin that is not registered for the app. Register that exact origin, port included. - The popup says "This app is not registered." Your page uses an app ID the local server does not know, for example one made before a reset. Put the current app ID in your page.
Use your own developer token
You do not need PB_TOKEN on the local server, but you can still give the CLI your own token: npx phibac mcp needs one, and so does an app made with your own token before the local server had its own key. Create one on http://localhost:8787/account/developer (type a name and press Create token; it is shown only once) and give it to the CLI in the terminal where you run it:
export PB_TOKEN=pbd_...
On the local server the CLI still uses ./.pb/developer-token first, and uses PB_TOKEN when that file is missing, or once more when the local key may not change an app. A token works only on the server that made it: on any other server it is refused with unauthorized. npx phibac mcp does not use the key file: it always needs PB_TOKEN, for the local server too.
A token from your own account does not own the apps that npx phibac init made on the local server: they belong to the server's built-in account, so changing them with your token is refused with forbidden, and the agent tools do not list them. To change a local app's origins yourself, run the curl command in Sign users in with $(cat ./.pb/developer-token) in place of $PB_TOKEN: the shell sends the key without printing it. Or start again with empty data (step 6).
Next step
Put your app on the internet takes your app from the local server to the real one.