Quickstart cipi.yml Web panel API MCP Ecosystem Guides Docs GitHub Telegram channel
  1. Home
  2. Guides
  3. Preview branches: a live URL for every branch, built into Cipi
Laravel

Preview branches: a live URL for every branch, built into Cipi

Give any branch of a Laravel, WordPress, Symfony, Node or Laravel Rust app its own address, database and HTTPS with one command — updated on every push, removed when the branch is deleted. From the CLI, the panel, the API or your pipeline, on your own VPS.

By Updated 11 min read

A reviewer opens a link and sees the branch running: the new checkout, the redesigned home page, the migration applied to real data. No pulling the branch, no "works on my machine", no shared staging that three people break at once.

Cipi has this built in. One command gives a branch its own address, its own database and its own HTTPS — a full copy of the app on the same server, deployed again at every push and removed when the branch is deleted.

bash
sudo cipi preview create shop feature/new-cart

It works for every app that deploys releases from a repository: Laravel (PHP-FPM and Octane), WordPress, Symfony, Node and Laravel Rust.

Key ideas, in plain words#

TermMeaning
PreviewA copy of an app, on another branch of the same repository, with an address of its own. For Cipi it is simply one more app
Server domainA domain that belongs to the server itself, not to one app: *.example.com. Cipi makes names under it for previews and webhooks
Wildcard DNS recordA record named * that sends every name under a domain to one server — anything.example.com included
WebhookThe call your Git provider makes after each push. It is what keeps a preview in step with its branch

Before you start#

You needWhy
A Cipi server with the app on itThe preview is made like that app: same type, PHP, build, deploy options
A domain whose DNS you controlFor the wildcard record of step 1
A Git provider token on the server (Git providers)Recommended: Cipi adds each preview's deploy key and webhook, and removes them with it. Without one you add the key by hand
Free disk and RAMA preview is a full app: a release, a database, a PHP pool or a Node process

1. Give the server its own domain#

At your DNS provider, add one record that points at the server:

TypeNameValue
A*the server's IPv4 address
AAAA*its IPv6 address, if it has one

Already using example.com for other things? Go a level down — name *.cipi, domain *.cipi.example.com — and nothing else under your domain is touched. A wildcard record never overrides the records you already have.

Then tell Cipi:

bash
sudo cipi server domain set '*.example.com'
The server's own domain
$ sudo cipi server domain set '*.example.com'

Cipi checks that the record really is a wildcard and really points here before it changes anything. Along with previews, the domain gives every app a Git webhook on https://webhooks.example.com/<app> — so a Laravel app deploys on push without the cipi/agent package (server domain). In the panel: the server's Domain section.

The Domain section of a server in the panel: the wildcard record *.example.com with its certificate installed, what Cipi does with it — a webhook for every app, previews of a branch, a name for the API — and the three previews that live under the domain The Domain section of a server in the panel: the wildcard record *.example.com with its certificate installed, what Cipi does with it — a webhook for every app, previews of a branch, a name for the API — and the three previews that live under the domain
Server → Domain: the wildcard record, the webhook address with its certificate, and the previews under it.

2. Create a preview#

Push the branch, then:

bash
sudo cipi preview create shop feature/new-cart
The preview of a branch
$ sudo cipi preview create shop feature/new-cart --db=copy
Step 1 of 5Name it

The address is <app>-<branch>-<random>.<domain>: shop-feature-new-cart-7asfy.example.com. The five random characters mean two previews never collide and the address is hard to guess — though not a secret: keep private previews behind basic auth.

OptionWhat it does
--db=emptyA new, empty database: the first deploy runs the migrations. The default
--db=copyA copy of the app's database, taken now
--db=noneNo database (not for a Laravel app)
--no-deployCreate it, deploy later — to change its .env first
--keepStays when its branch is deleted
--no-sslNo certificate now

From the app's side it reads the same: sudo cipi app feature-branch shop feature/new-cart. The preview's name — shopfeaturenew7asfy here — is the Linux user and the database; the command prints it, and sudo cipi preview list lists them all.

A preview is an app. Everything you know works on it by its name: sudo cipi deploy, sudo cipi app logs, sudo cipi app env, sudo cipi app run, sudo cipi basicauth, sudo cipi worker add.

3. Choose its data#

Use it whenMind
Empty (default)The app seeds itself; the change is code, not dataRun your seeders once: sudo cipi app artisan <preview> db:seed --force (Laravel), or the console command of your framework
CopyA migration or an upgrade must be tried on real data; a WordPress or WooCommerce site whose content is the dataPersonal data travels with it. For Laravel, an anonymized dump is safer for previews many people open
NoneA Node front end with no database of its own—

A copy is taken once, when the preview is made. Later pushes run the branch's migrations on that copy, never on production.

4. Every push updates it#

A push to the branch deploys the preview, the way a push deploys the app: a new release beside the live one, one switch. The preview's webhook is on the server's domain — https://webhooks.example.com/<preview> — and is registered on the repository with the provider token.

bash
sudo cipi app webhook show shopfeaturenew7asfy        # where its pushes go
sudo cipi app webhook auto shopfeaturenew7asfy off    # stop following the branch for now
sudo cipi deploy shopfeaturenew7asfy                  # deploy it by hand

5. Keep it safe#

A preview is a real app on the internet, with a copy of your configuration. Four things to decide once:

What to do
E-mailThe .env is copied with the mail settings. Create with --no-deploy, then point mail away from real people — MAIL_MAILER=log (Laravel), MAILER_DSN=null://null (Symfony), an SMTP sandbox such as Mailpit — and deploy
Payments and APIsSwap live keys for test keys: Stripe, PayPal, webhooks to third parties, a separate storage bucket
PrivacyBasic auth keeps search engines and strangers out: sudo cipi basicauth enable <preview>. Its webhook is on the server's domain, so pushes still deploy. For company logins, put previews behind Cloudflare Zero Trust
DataWith --db=copy, the preview holds what production holds. Give it only to people who may see it, or use an anonymized dump
bash
sudo cipi preview create shop feature/new-cart --db=copy --no-deploy
sudo cipi app env shopfeaturenew7asfy --set=MAIL_MAILER=log
sudo cipi app env shopfeaturenew7asfy --set=STRIPE_SECRET=sk_test_…
sudo cipi basicauth enable shopfeaturenew7asfy --user=review
sudo cipi deploy shopfeaturenew7asfy

6. A configuration just for previews#

A preview's environment is preview. When the app applies its cipi.yml after every deploy, the preview reads cipi-preview.yml first, if the repository has one. Keep previews small:

yaml
# cipi-preview.yml
version: 1
workers:
  queues:
    - { queue: default, processes: 1 }   # one worker is plenty for a review
schedule: false                          # no scheduled jobs on previews
deploy:
  keep_releases: 2                       # less disk per preview

Turn auto-apply on for the app — sudo cipi yml auto shop on — and each new preview has it on too.

7. From the panel#

Every app that can have previews has a Previews section: type a branch, pick the database, tick Keep if it is for a demo, create. The list shows each preview with its address, its database, whether pushes deploy it, and a delete button.

The Previews section of the app shop in the panel: two previews, feature/new-cart and fix/invoice-rounding, each with its address under example.com, its own database and On push; and the New preview form with a branch, the database — a new empty one or a copy — and Keep it when the branch is deleted The Previews section of the app shop in the panel: two previews, feature/new-cart and fix/invoice-rounding, each with its address under example.com, its own database and On push; and the New preview form with a branch, the database — a new empty one or a copy — and Keep it when the branch is deleted
An app's Previews: the branches that have one, and the form for the next.

In the Apps list, previews sit under the app they come from, called by their branch, so a server with twenty previews still reads as five apps:

The Apps list of the panel across three servers: Laravel, Symfony, WordPress, Node and custom apps; under shop, two previews named by their branches, feature/new-cart and fix/invoice-rounding, and under shopapi the preview feature/v2-endpoints, each with its own address The Apps list of the panel across three servers: Laravel, Symfony, WordPress, Node and custom apps; under shop, two previews named by their branches, feature/new-cart and fix/invoice-rounding, and under shopapi the preview feature/v2-endpoints, each with its own address
Apps: each preview is a row of its app, with its own Deploy and Manage.

A preview's own page says whose preview it is, and has every section an app has — logs, environment, commands, deploys.

8. One preview per pull request, from CI#

The built-in command needs no script: a pipeline calls the REST API once when a pull request opens, and deleting the branch after the merge does the rest. On the server, a token that may only create previews and touch their .env and deploys:

bash
sudo cipi api token create --name=previews \
    --abilities=apps-view,apps-create,apps-env,deploy-manage --expires=2027-12-31

Save it as CIPI_API_TOKEN and the API's address as CIPI_API_URL in the repository's secrets. Then:

yaml
# .github/workflows/preview.yml
name: Preview
on:
  pull_request:
    types: [opened, reopened]

jobs:
  preview:
    runs-on: ubuntu-latest
    steps:
      - name: Create the preview of the branch
        env:
          API: ${{ secrets.CIPI_API_URL }}
          TOKEN: ${{ secrets.CIPI_API_TOKEN }}
          BRANCH: ${{ github.head_ref }}
        run: |
          H="Authorization: Bearer $TOKEN"
          wait_job() {   # poll a job until it ends; print its result
            for i in $(seq 1 180); do
              j=$(curl -fsS "$API/api/jobs/$1" -H "$H")
              case "$(jq -r '.data.status' <<< "$j")" in
                completed) jq -c '.data.result' <<< "$j"; return 0 ;;
                failed)    jq -r '.data.output' <<< "$j"; return 1 ;;
              esac
              sleep 5
            done
            return 1
          }
          # 1. the preview, with a copy of the database, not deployed yet
          job=$(curl -fsS -X POST "$API/api/apps/shop/previews" -H "$H" -H "Content-Type: application/json" \
            -d "$(jq -n --arg b "$BRANCH" '{branch: $b, db: "copy", deploy: false}')" | jq -r '.job_id')
          result=$(wait_job "$job")
          name=$(jq -r '.preview' <<< "$result"); url=$(jq -r '.url' <<< "$result")
          # 2. no real e-mail, test keys
          curl -fsS -X PUT "$API/api/apps/$name/env" -H "$H" -H "Content-Type: application/json" \
            -d '{"set":{"MAIL_MAILER":"log","STRIPE_SECRET":"sk_test_..."}}' > /dev/null
          # 3. the first deploy
          wait_job "$(curl -fsS -X POST "$API/api/apps/$name/deploy" -H "$H" | jq -r '.job_id')" > /dev/null
          echo "### Preview: $url" >> "$GITHUB_STEP_SUMMARY"

From then on, pushes to the branch deploy the preview through its own webhook, and the branch deletion after the merge removes it. On GitLab, the same three calls go in a job with rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event". The cipi-cli and the PHP SDK have the same commands: cipi-cli previews create shop feature/new-cart, $cipi->previews()->create('shop', 'feature/new-cart', ['db' => 'copy']).

Want previews made and removed by your pipeline instead — for every pull request, closed with it, on a server of their own, with a script you control? That is the pipeline-driven way. Both can live side by side.

9. When it goes#

What happensThe preview
The branch is deleted on the Git providerRemoved within a few minutes — Cipi asks the repository itself before it deletes anything
The branch is merged, and keptStays. Turn on Automatically delete head branches (GitHub) or Delete source branch (GitLab)
The repository can't be reachedStays: a network error is never read as a deleted branch
It was made with --keepStays until you delete it
You delete itsudo cipi preview delete shopfeaturenew7asfy, or the panel's delete button

Removing a preview removes its address, certificate, database, files, and its deploy key and webhook on the repository. A check every five minutes does the sweeping; a preview without a webhook is asked about every half hour.

bash
sudo cipi preview list              # every preview on the server
sudo cipi preview list shop         # those of one app
sudo cipi preview keep shopfeaturenew7asfy on
sudo cipi preview delete shop feature/new-cart

Good to know#

The app's own branchIs not a preview: a preview of main, when the app deploys main, is refused
One per branchA second preview of the same branch is refused, with the name of the first
A preview of a previewRefused: make it from the app
WorkersA Laravel preview gets its queue worker and scheduler like the app (tune them in cipi-preview.yml). A Symfony preview starts with none: sudo cipi worker add <preview> --queue=async
Media of a WordPress copyThe preview's uploads folder starts empty; copy it if reviewers need the images
A public repository that is not yoursThe preview is made, and deploys when you ask: nobody but the owner can add a webhook to it
Behind a Cloudflare tunnel or a mesh lockPorts 80 and 443 are closed to the world, so previews and webhooks.<domain> can't be reached directly. Publish a branch through the tunnel with sudo cipi zt preview create
Changing the server's domainRefused while previews live under it: delete them first

Troubleshooting#

ProblemFix
Previews live under the server's domain, and none is setStep 1: sudo cipi server domain set '*.example.com'
… is not a wildcardYou created webhooks.example.com only: add the * record
The repository of 'shop' has no branch …Push the branch first. The command lists the branches it found
Deploy: not run — the preview's deploy key cannot read the repository yetNo provider token: sudo cipi deploy <preview> --key, add it to the repository as read-only, then sudo cipi deploy <preview>
A custom app has no previewsCustom apps have no releases. Move the app to its type (WordPress, Symfony) if it lives in Git
The preview shows production's links (WordPress)Links inside posts point at the live domain: sudo cipi app run <preview> wp search-replace 'https://blog.example.com' 'https://<preview address>' --all-tables
Pushes don't update itsudo cipi app webhook show <preview>: whether the provider has the hook, and whether automatic deploys are on
It is still there after the mergeThe branch wasn't deleted. Delete it, or sudo cipi preview delete <preview>

Every command and option: Preview environments in the docs.

Questions

What does a preview cost?

Nothing in licences: it is one more app on a server you already pay for. It takes disk (a release, a database) and some RAM while it runs. Delete the ones nobody looks at — or let the branch deletion do it.

Which apps can have previews?

Laravel (PHP-FPM and Octane), WordPress, Symfony, Node and Laravel Rust apps — every type that deploys releases from a repository. A custom app has no releases to preview.

Do I need a wildcard certificate?

No. Each preview gets a normal Let's Encrypt certificate for its own name. What you need is a wildcard DNS record, which every DNS provider offers for free.

Is my production database at risk?

No. A preview never uses the app's database: it gets a new one, empty or a copy taken when the preview is made. Writes on the preview stay there.

Does a preview send e-mails to real users?

It can: the app's .env is copied, mail settings included. Create it with --no-deploy, point mail at a log or a sandbox with sudo cipi app env <preview>, then deploy. The pipeline recipe below does it for you.

What happens when the branch is merged?

If your Git provider deletes merged branches (turn it on), the preview goes within minutes. A merged branch that is kept keeps its preview until you delete it.

Can I keep a preview for a demo?

Yes: --keep when you create it, or sudo cipi preview keep <preview> on later. It stays when its branch is deleted, until you remove it.

Can previews live on another server than production?

Yes, and for busy teams it is the better setup: one Cipi server for previews, with its own domain, and production left alone. The app has to exist there too — cipi sync copies it.

Try it on your own server

Free and open source. One command on a fresh Ubuntu 24.04 or 26.04 VPS.

wget -O - https://cipi.sh/setup.sh | bash
Read the quickstart