Docs cipi.yml Web panel API MCP Guides Compare GitHub Telegram channel
  1. Home
  2. Guides
  3. Preview environments for every Laravel branch
Laravel

Preview environments for every Laravel branch

Give every branch its own live URL with a database, workers and HTTPS, created on the first push and deleted with the branch, using GitHub Actions and a wildcard certificate.

By Updated 2 min read

Reviewers click a link instead of pulling a branch. Each preview is a complete, isolated Cipi app at feature-x-shop-3a1f9c2e.preview.example.com, removed when the branch is deleted.

Key ideas, in plain words#

TermMeaning
Preview environmentA temporary copy of the app for one branch or pull request
Wildcard certificateOne HTTPS certificate for every *.preview.example.com
SlugThe branch name made safe for a domain and a Linux user: feature/cart → pr-cart
Step 1 of 5Push feature/x

A developer pushes any branch except main.

1. One-time setup#

StepHow
Wildcard DNSA *.preview.example.com → server IP
Wildcard certificateDNS-01 with Cloudflare: see wildcard domains
Repository accessA read-only token so previews need no deploy key per app
CI secretsSERVER_HOST, SERVER_SSH_KEY, DEPLOY_WILDCARD_DOMAIN

2. The script and the workflow#

The complete, copy-paste versions of .cipi/preview.sh and .github/workflows/preview.yml are in the preview environments docs. The idea:

bash
# up: create once, deploy every push
cipi app show "$APP" &>/dev/null || cipi app create --user="$APP" --domain="$DOMAIN" \
    --repository="$REPO" --branch="$BRANCH"
cipi deploy "$APP"
# down: when the branch is deleted
cipi app delete "$APP" --force

The app name is a short hash of branch and repository, so it's stable for the branch and never collides.

3. Make previews useful#

AddHow
Realistic data without personal dataImport an anonymized dump after create
A login in frontbasic_auth in cipi-preview.yml, with --env=preview on create
Fewer resourcesOne worker, no backups, in the same file
A link in the pull requestPost https://$DOMAIN as a PR comment from the workflow

4. Clean up#

The workflow's delete trigger removes the app. Check for leftovers now and then with sudo cipi app list.

Troubleshooting#

ProblemFix
App name refusedNames must be lowercase alphanumeric: sanitize the branch slug and keep it short
Preview has no HTTPSWildcard certificate missing: see wildcard domains
Leftover previewssudo cipi app list and delete; check the workflow's delete trigger
Previews send real e-mailsSet MAIL_MAILER=log (or a sandbox) for previews

Questions

Does each preview get its own database?

Yes. Each preview is a full Cipi app with its own user, database, worker and .env.

What data do previews start with?

Empty, migrated and seeded by your seeders. For realistic data, restore an anonymized dump, never production.

How many previews fit on a server?

Each idle app is light (a PHP pool, a worker, a small database). A 4 GB server comfortably runs a dozen small previews.

How do I keep previews private?

Turn on basic auth for them (cipi basicauth enable) or put them behind Cloudflare Zero Trust.

What if a step fails?

Read the troubleshooting table above first. Then check the matching docs page, open a GitHub issue, or ask in the community. Most commands print the fix when they refuse something.

Do I need the web panel for this?

No. Every step works from the CLI. The optional web panel shows the same things in a browser.

Can I run these commands from my laptop?

Many of them, through cipi-cli and the API, with a scoped token. Otherwise ssh cipi@your-server and use sudo cipi ….

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