# 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.

URL: https://cipi.sh/guides/preview-branches · Last updated: 2026-12-03 · By Andrea Pollastri · 11 min read · Category: Laravel

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**.

1. **Server domain** — one wildcard record
2. **Create** — a URL, a database, HTTPS
3. **Data** — empty, or a copy
4. **Safe** — mail, keys, privacy
5. **CI** — one per pull request
6. **Gone** — with the branch

## Key ideas, in plain words

| Term | Meaning |
| --- | --- |
| **Preview** | A 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 domain** | A domain that belongs to the server itself, not to one app: `*.example.com`. Cipi makes names under it for previews and webhooks |
| **Wildcard DNS record** | A record named `*` that sends every name under a domain to one server — `anything.example.com` included |
| **Webhook** | The call your Git provider makes after each push. It is what keeps a preview in step with its branch |

## Before you start

| You need | Why |
| --- | --- |
| A Cipi server with the app on it | The preview is made like that app: same type, PHP, build, deploy options |
| A domain whose DNS you control | For the wildcard record of [step 1](https://cipi.sh/guides/preview-branches#domain) |
| A Git provider token on the server ([Git providers](https://cipi.sh/docs/git)) | 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 RAM | A 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:

| Type | Name | Value |
| --- | --- | --- |
| `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:

```console
$ sudo cipi server domain set '*.example.com'
[INFO] Server domain: *.example.com
✓ DNS: *.example.com is a wildcard
✓ Saved
→ Webhook endpoint (webhooks.example.com)...
✓ Webhook endpoint ready — 5 app(s)
→ Certificate for webhooks.example.com...
✓ Certificate installed for webhooks.example.com
✓ blog: GitHub webhook → https://webhooks.example.com/blog
✓ billing: GitHub webhook → https://webhooks.example.com/billing

  Webhooks   https://webhooks.example.com/<app>  — no cipi/agent needed
  API        not installed — cipi api suggests api.example.com
  Previews   cipi preview create <app> <branch> → <app>-<branch>-<random>.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](https://cipi.sh/docs/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](https://cipi.sh/img/gui/server-domain-light.webp)

*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:

```console
$ sudo cipi preview create shop feature/new-cart --db=copy
[INFO] Preview of 'shop', branch 'feature/new-cart' → shopfeaturenew7asfy
→ Creating 'shopfeaturenew7asfy' (laravel)...
✓ User   ✓ Database   ✓ Deploy key on GitHub   ✓ Webhook
✓ PHP-FPM 8.5   ✓ Nginx → shop-feature-new-cart-7asfy.example.com
✓ The .env of 'shop', with the preview's own keys, database and URL
→ Copying database shop → shopfeaturenew7asfy...
✓ Database copied
✓ Certificate installed for shop-feature-new-cart-7asfy.example.com
task deploy:update_code     feature/new-cart @ 4be91d0
task deploy:vendors
task artisan:migrate
✓ Deploy completed  (release 1, 1m12s)

  PREVIEW: shopfeaturenew7asfy  of shop, branch feature/new-cart
  URL        https://shop-feature-new-cart-7asfy.example.com
  Database   shopfeaturenew7asfy (mariadb, a copy of shop's)
  Deploy     released ✓
  Push       a push to 'feature/new-cart' deploys it
  Removed    when 'feature/new-cart' is deleted from the repository
```

1. **Name it** — readable and unique
   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](#safe).
2. **Make the app** — like the one it comes from
   Same type, PHP version, Node version, build command, document root and deploy options. A Linux user, a PHP pool (or a Node process), a deploy key and a webhook of its own.
3. **Copy the .env** — without what is the app's own
   Everything is carried over except the app's keys and salts, its URLs, its database, its Valkey, Reverb and search settings: the preview gets its own.
4. **Data** — its own database
   New and empty, or a copy of the app's. Never the app's database.
5. **HTTPS and deploy** — minutes
   A Let's Encrypt certificate for its name, then the first deploy of the branch.

| Option | What it does |
| --- | --- |
| `--db=empty` | A new, empty database: the first deploy runs the migrations. **The default** |
| `--db=copy` | A copy of the app's database, taken now |
| `--db=none` | No database (not for a Laravel app) |
| `--no-deploy` | Create it, deploy later — to change its `.env` first |
| `--keep` | Stays when its branch is deleted |
| `--no-ssl` | No 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 when | Mind |
| --- | --- | --- |
| **Empty** (default) | The app seeds itself; the change is code, not data | Run your seeders once: `sudo cipi app artisan <preview> db:seed --force` (Laravel), or the console command of your framework |
| **Copy** | A migration or an upgrade must be tried on real data; a WordPress or WooCommerce site whose content *is* the data | Personal data travels with it. For Laravel, an [anonymized dump](https://cipi.sh/guides/anonymized-database-dumps) is safer for previews many people open |
| **None** | A 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-mail** | The `.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 APIs** | Swap live keys for test keys: Stripe, PayPal, webhooks to third parties, a separate storage bucket |
| **Privacy** | Basic 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](https://cipi.sh/docs/zero-trust) |
| **Data** | With `--db=copy`, the preview holds what production holds. Give it only to people who may see it, or use an [anonymized dump](https://cipi.sh/guides/anonymized-database-dumps) |

```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`](https://cipi.sh/docs/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](https://cipi.sh/img/gui/app-previews-light.webp)

*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](https://cipi.sh/img/gui/apps-light.webp)

*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](https://cipi.sh/docs/api#previews) 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](https://cipi.sh/docs/cli-client) and the [PHP SDK](https://cipi.sh/docs/php-sdk) have the same commands: `cipi-cli previews create shop feature/new-cart`, `$cipi->previews()->create('shop', 'feature/new-cart', ['db' => 'copy'])`.

> [!TIP]
> 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](https://cipi.sh/guides/laravel-preview-environments). Both can live side by side.

## 9. When it goes

| What happens | The preview |
| --- | --- |
| The branch is **deleted** on the Git provider | Removed within a few minutes — Cipi asks the repository itself before it deletes anything |
| The branch is merged, and kept | Stays. Turn on *Automatically delete head branches* (GitHub) or *Delete source branch* (GitLab) |
| The repository can't be reached | Stays: a network error is never read as a deleted branch |
| It was made with `--keep` | Stays until you delete it |
| You delete it | `sudo 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 branch | Is not a preview: a preview of `main`, when the app deploys `main`, is refused |
| One per branch | A second preview of the same branch is refused, with the name of the first |
| A preview of a preview | Refused: make it from the app |
| Workers | A 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 copy | The preview's uploads folder starts empty; copy it if reviewers need the images |
| A public repository that is not yours | The 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 lock | Ports 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`](https://cipi.sh/docs/zero-trust#previews) |
| Changing the server's domain | Refused while previews live under it: delete them first |

## Troubleshooting

| Problem | Fix |
| --- | --- |
| *Previews live under the server's domain, and none is set* | [Step 1](https://cipi.sh/guides/preview-branches#domain): `sudo cipi server domain set '*.example.com'` |
| *… is not a wildcard* | You 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 yet* | No 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 previews* | Custom apps have no releases. Move the app to its type ([WordPress](https://cipi.sh/guides/wordpress-git-zero-downtime), [Symfony](https://cipi.sh/guides/deploy-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 it | `sudo cipi app webhook show <preview>`: whether the provider has the hook, and whether automatic deploys are on |
| It is still there after the merge | The branch wasn't deleted. Delete it, or `sudo cipi preview delete <preview>` |

Every command and option: [Preview environments](https://cipi.sh/docs/preview-environments) in the docs.

## Reference docs

- [Preview environments](https://cipi.sh/docs/preview-environments)
- [Server domain](https://cipi.sh/docs/server-domain)
- [Auto-deploy on push](https://cipi.sh/docs/auto-deploy)
- [cipi.yml](https://cipi.sh/docs/yml)
- [Basic auth](https://cipi.sh/docs/basic-auth)
- [REST API](https://cipi.sh/docs/api)

## 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.

---

Index of every page: https://cipi.sh/llms.txt · Everything in one file: https://cipi.sh/llms-full.txt · Source: https://github.com/cipi-sh/cipi (MIT)
