Docs cipi.yml Web panel API MCP Guides Compare GitHub Telegram channel
  1. Home
  2. Guides
  3. Staging and production from one repository with cipi.yml
cipi.yml

Staging and production from one repository with cipi.yml

A beginner-friendly walkthrough to run a staging copy and a production copy of the same Laravel app, each deploying its own branch with its own settings, driven by cipi-staging.yml and cipi.yml.

By Updated 4 min read

Most teams want two copies of the same app: production, which your customers use, and staging, where you try changes first. This guide sets that up on Cipi from scratch, explaining each idea along the way. No previous Cipi experience needed.

What you'll build#

  • Git repositoryone codebase, two branches
  • shop (production)branch main → reads cipi.yml
  • shop-stg (staging)branch develop → reads cipi-staging.yml
ProductionStaging
App name (Linux user)shopshop-stg
Domainshop.example.comstaging.shop.example.com
Branch that deploysmaindevelop
Settings filecipi.ymlcipi-staging.yml
Databaseshopshop-stg (separate)
Who can see iteveryoneonly your team (password)

Key ideas, in plain words#

TermMeaning
AppOne running copy of your code on the server: its own user, folder, PHP pool, database and domain
EnvironmentA label on an app (production, staging…). Laravel sees it as APP_ENV, Cipi uses it to pick a settings file
BranchThe Git branch an app deploys. Push to it and that app updates
cipi.ymlA file in your repository that describes how the server should run the app: PHP version, workers, backups… (what it is)
Plan / applyCipi first shows what the file would change (plan), then does it (apply)

Before you start#

  • A server with Cipi and your production app already running (Deploy Laravel on a VPS).
  • A develop branch in your repository: git checkout -b develop && git push -u origin develop.
  • A DNS record for staging.shop.example.com pointing at the server (same IP as production).

1. Create the staging app as a clone#

A clone copies the app's configuration (PHP version, repository, workers, deploy settings) into a new, fully separate app:

bash
sudo cipi app clone shop --domain=staging.shop.example.com --name=shop-stg \
    --branch=develop --env=staging --with-db
FlagWhy
--domainThe address of the new app
--nameIts Linux user and app name
--branch=developStaging deploys the develop branch
--env=stagingMarks it as staging: it will read cipi-staging.yml and get APP_ENV=staging
--with-dbCreates a fresh, empty database for it

The clone gets new database credentials, its own deploy key, its own Reverb credentials and search key. Nothing points back to production. Save the summary it prints.

Then deploy it once and add HTTPS:

bash
sudo cipi deploy shop-stg
sudo cipi ssl install shop-stg
Deploy, list releases, roll back
$ cipi deploy shop
$ cipi deploy shop --releases
$ cipi deploy shop --rollback

2. Keep strangers out of staging#

Staging often contains unfinished features. Put a password in front of it:

bash
sudo cipi basicauth enable shop-stg --user=preview --password='a-long-random-passphrase'

Pick a long password and share it with your team (without --user and --password, Cipi generates both and shows them once). Search engines and visitors now get a login prompt.

3. Write the two settings files#

In your repository root, production keeps its cipi.yml. Add a second file, cipi-staging.yml, with what staging needs. The staging file does not inherit from cipi.yml: write everything staging needs.

yaml
# cipi.yml — production
version: 1
app:
  php: "8.6"
  aliases: ["www.shop.example.com"]
  www: to-root
workers:
  horizon: true
schedule: true
health:
  url: "https://shop.example.com/up"
  rollback_on_unhealthy: true
deploy:
  branch: main
  predeploy_snapshot: true
env: { required: [STRIPE_KEY, MAIL_HOST] }
backup:
  profiles:
    - { name: shop-nightly, scope: all, cron: "0 2 * * *", keep_days: 14, destinations: [s3], encrypt: true }
yaml
# cipi-staging.yml — staging
version: 1
app:
  php: "8.6"
  basic_auth:
    users: [preview]           # the user created above; keeps its password
workers:
  queues:
    - { queue: default, processes: 1 }
schedule: true
deploy:
  branch: develop
env: { required: [STRIPE_KEY] }   # test keys, set on the staging server
DifferenceWhy
No aliases or www redirectStaging has one domain
One queue worker instead of HorizonLess memory; enough for testing
No backup profileStaging data is disposable
basic_auth in the fileThe password protection can't be removed by accident
deploy.branch: developPushes to develop deploy staging

Validate both before you commit (with the Cipi Agent installed in the app):

bash
php artisan cipi:yml validate
CIPI_ENV=staging php artisan cipi:yml validate

Commit and push to both branches (merge develop into main later, or cherry-pick the files).

4. Plan, then apply on staging#

After the next deploy of shop-stg the file is on the server. See what it would change:

cipi.yml
$ cipi yml plan shop
$ cipi yml apply shop
$ cipi yml auto shop on
bash
sudo cipi yml plan shop-stg
sudo cipi yml apply shop-stg
sudo cipi yml auto shop-stg on      # apply after every deploy from now on

Do the same for production with shop. From now on, the files are the source of truth: change them in a pull request, merge, and each app applies its own file on the next deploy.

5. Push-to-deploy for each branch#

Each app has its own webhook and only deploys its own branch:

Step 1 of 4git push develop

You push to develop. GitHub calls the webhook of the staging app.

Get each app's webhook URL and secret with sudo cipi deploy shop-stg --webhook and add it to the repository (auto-deploy). Pushes to other branches answer skipped.

6. Get realistic data into staging#

An empty database isn't much of a test. Never copy production as is: personal data ends up in a less protected place. Use an anonymized dump:

bash
cipi-cli prod db anonymize shop --email you@example.com
cipi-cli db anonymize download "<signed link>" -o shop-anon.sql
# copy it to the server, then:
sudo cipi db restore shop-stg /home/cipi/shop-anon.sql

Step by step: GDPR-safe production data.

The daily workflow#

Step 1 of 4Branch

Create a feature branch from develop and work there.

Troubleshooting#

ProblemFix
cipi yml plan shop-stg says it reads cipi.ymlThe app's env isn't staging: sudo cipi app edit shop-stg --env=staging
Plan says "blocked: STRIPE_KEY missing"Set it on the staging app: sudo cipi app env shop-stg --set=STRIPE_KEY=sk_test_…
Staging deploys maindeploy.branch is applied from the next deploy, or set it now: sudo cipi app edit shop-stg --branch=develop
Invalid cipi-staging.ymlThe error names the file; validate locally with CIPI_ENV=staging php artisan cipi:yml validate
Staging sends real e-mailsUse a mail catcher or a sandbox SMTP in the staging .env

Questions

What is the difference between an "app" and an "environment" here?

On Cipi every running copy of your code is an app with its own Linux user, database and domain. "Environment" is a label on the app (production, staging, preview…) that decides which settings file it reads. Two environments of the same project are two apps.

Do staging and production share a database?

No. The staging app has its own database and credentials. Copy data in on purpose, ideally an anonymized dump, never by pointing staging at production.

Can staging and production be on different servers?

Yes, and it's often wiser. Create the staging app on the other server with --env=staging; it reads the same cipi-staging.yml from the same repository.

Which file wins if both cipi.yml and cipi-staging.yml exist?

An app with env staging reads cipi-staging.yml. If that file doesn't exist it falls back to cipi.yml. If it exists but is invalid, nothing is applied and the error names the file: there is no silent fallback.

Can a developer make production read the staging file by committing something?

No. The environment is set on the server (--env), never in the file. A commit can change what a file says, not which file an app reads.

How do I keep production settings out of staging, like backups to S3?

Put them only in cipi.yml. The staging file starts from nothing: it doesn't inherit from cipi.yml, so anything you don't write in it isn't applied to staging.

What about secrets that differ, like Stripe test keys?

Keep them in each app's .env on the server (cipi app env shop-stg --set=STRIPE_KEY=…). Both files can require them by name with env.required, so a missing key blocks the plan.

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