# Staging, live, and preview environments

> Every site starts on staging. Launch live when you are ready, promote changes from staging to live, and use preview environments for bigger work.

Source: https://docs.wpwaterfall.com/environments

Every WP Waterfall site starts on **staging**. You build there, then launch **live** when the site is ready. After that, every code change starts on staging and reaches live through a **promote**. Nobody can change live's code from wp-admin, SFTP, or a hacked plugin. Uploads on live work as normal, and live owns them.

## What is an environment?

An environment is a database, an uploads folder (`wp-content/uploads`), and a release of your code, running in its own container on its own temporary hostname.

| Role | What it runs | What you do there |
|---|---|---|
| Staging | A read-only release of the `master` branch (Git mode). In SFTP mode, a writable working tree of it. | Build and test. Push code with Git, or switch to SFTP mode to install plugins in wp-admin or edit over SFTP, then commit. |
| Live | A read-only release promoted from staging. | Your public site. Uploads and content change as usual. |
| Preview | A read-only release of the Git branch with the environment's name (Git mode). In SFTP mode, a writable working tree. | Bigger changes and experiments, merged into staging when ready. |

The environment switcher at the top of the site shows which environment you are on, with the environment name as a colored badge: amber for staging, green for live, violet for a preview. Every tab works on that environment, and the page address keeps it (`?env=`), so a shared link opens the same one. The switcher lists live, then staging, then previews, newest first. **Manage environments** opens a page with every environment. While a site is first being set up, the switcher lists staging alone: **Launch live** and **Create environment** show once staging is up.

## What does a new site start with?

WP Waterfall creates staging: WordPress on the `master` branch of a new repository, with its own database, uploads, and address such as `staging-acme.wpwaterfall.dev`. See [Temporary domain](https://docs.wpwaterfall.com/temporary-domain). Search engines and AI crawlers are kept out. See [Staging privacy](https://docs.wpwaterfall.com/staging-privacy).

## How do I change code on staging?

Use the **Code** card on staging's **Info** page. Staging and previews start in Git mode, where code changes only by a Git push, a merge, a pull from a connected repository, a promote, or a reset from live. Switch to SFTP mode to install in wp-admin or edit over SFTP, then **Commit changes**. The card also shows **Commit history** with a **Diff** on each commit, and says how many commits live lacks. See [Git access](https://docs.wpwaterfall.com/git-access) for the modes, [Git access](https://docs.wpwaterfall.com/git-access#how-do-i-clone-and-push) for SSH keys, [Connect GitHub, GitLab, or Bitbucket](https://docs.wpwaterfall.com/connect-github) for an external repository, and [Deploys, rollback, and the Code card](https://docs.wpwaterfall.com/code-tab) for where each task lives.

## How do I launch live?

Choose **Launch live** on staging's Info tab, in the switcher, or in the top bar. A preview's Info tab does not offer it. Launching adds no charge, because live uses the site license the site already holds. WP Waterfall creates live from staging: a copy of staging's database and uploads, the code staging runs, its own address such as `live-acme.wpwaterfall.dev`, and a certificate. Live lets search engines in. Staging stays as it was.

Staging must be running with its changes committed, because live starts from staging's last commit. If a launch fails, staging is untouched: delete the failed live environment and launch again.

API: `POST /v1/sites/{id}/launch` with `{"confirm": true}`.

## Deploy staging to live

Pick **Live** in the switcher. The first card on **Info** is **Deploys**. On the **Environments** page, **Deploys** next to an environment in Git mode opens the list of its deploys.

1. WP Waterfall compares staging with live each time the page opens. With nothing new, it says "Live is up to date with staging. Nothing to deploy." Otherwise it says how many commits and files are ready and lists them under **Changes to deploy**: each commit shows its title, author, and age, with a **Diff** button. A long message folds to two lines, and **Show more** opens it.
2. If something blocks the deploy, the card says what and how to fix it. Uncommitted changes on staging in SFTP mode show **Commit changes on staging**. You can also deploy with a commit message, which commits them first.
3. Add an optional deploy note. Only code moves. Live keeps its own database and uploads.
   - **Copy new uploads from staging** merges uploads into live. It adds files live lacks and files that changed on staging, and the dialog counts them first: new, updated, and "differ and are newer on live". It never deletes a live file, keeps a live file newer than staging's copy, and never copies PHP files.
   - **Overwrite files that differ** also replaces the newer live files. It asks for the overwrite confirmation and still deletes nothing.
   - Before content moves, WP Waterfall takes a restore point of live that includes its uploads.
4. Choose **Deploy to live** and type the site name. WP Waterfall builds the commit, takes a restore point, and switches live to the new code in one step. If a deploy hook fails, live keeps its code.

**Deployment history** lists each deploy: the commit message, who deployed it, and when, with **Roll back** on earlier releases. The **Promote to live** button in the **Environment details** card on staging does the same. If someone changed staging after you opened the dialog, the promote stops and asks you to look again.

To undo a deploy, choose **Undo** when it finishes, or **Roll back** on an earlier release. Restore the restore point to undo copied content.

API: `GET /v1/sites/{id}/promote/preview`, then `POST /v1/sites/{id}/promote` with `{"confirm": true, "sha": "<staging commit>"}`. Add `"commit_message"` to commit staging's changes first. Add `"database"` with `"confirm_content_overwrite": true` to copy tables. Add `"uploads"` (`"all"` or a list of folders) to merge uploads; the preview shows `content.uploads_merge` with `new_files`, `changed_files`, and `conflict_files`. Add `"uploads_overwrite": true` with `"confirm_content_overwrite": true` to replace newer live files.

## How do preview environments work?

A preview is a copy of staging, or of another environment, for trying a change without touching it. Choose **Create environment** in the switcher or on **Manage environments**, name it (such as `qa` or `checkout`), and pick what to **Copy from**: staging by default, or live or another preview that runs. The name cannot be `master`, `main`, `live`, `staging`, or `HEAD`, cannot start with `live-`, `staging-`, or `n-`, cannot hold a slash, and cannot be the name of another environment of the site. A name that cannot be used is named under the **Name** field, and the dialog keeps what you typed. WP Waterfall makes a Git branch with that name from the last commit of the environment you copy, clones its database and uploads, and builds the preview in Git mode. Commit uncommitted SFTP changes in that environment first. A new WordPress install or an empty environment is not offered. If the new environment cannot be made, WP Waterfall removes it and keeps its Git branch. The job and the bell say "WP Waterfall could not create the environment qa and removed it, so you can create it again." You can create one with the same name at once. When the 5 included previews are used, the same dialog sells more: pick a quantity and click **Buy and create**.

After **Create environment**, **Manage environments** opens with the new preview listed as **Setting up**. The switcher and the Sites list show it the same way. While the server builds it, the new environment's tabs show **Creating {name} environment** with progress. You can leave.

API: `POST /v1/sites/{id}/environments` with `{"kind": "preview", "name": "qa"}`. Add `"from_env_id"` to copy another environment of the site. A refusal of the name lists the field `name` in `errors`.

API: `POST /v1/sites/{id}/environments` with `{"name": "qa"}`. An environment with a name of its own is a preview: the answer says `"kind": "preview"` and `"role": "preview"`, whatever `kind` the request sent. Only the environment named `staging` has the kind `staging`.

- **Included:** every site has staging and 5 previews on every plan. They share the server and run on a small profile, so they never slow live (see [Site resources](https://docs.wpwaterfall.com/site-resources)). A higher [site tier](https://docs.wpwaterfall.com/site-tiers) on one environment gives it more PHP threads and memory.
- **Additional:** the sixth preview and each after it is an additional preview environment. You buy it in the **Create environment** dialog, up to 25 per site. See [Additional Preview Environments](https://docs.wpwaterfall.com/additional-preview-environments).
- **Sleeping:** idle previews stop, and the first visit starts them in a few seconds. **Wake up** on the Info tab starts one at once. Live never sleeps. See [Sleeping environments](https://docs.wpwaterfall.com/sleeping-environments).
- **Capacity:** WP Waterfall never turns down an included environment because a server is busy. It adds capacity and places new sites elsewhere.

### How do I merge a preview into staging?

A preview's **Code** card compares it with staging. When it has commits staging lacks, **Merge into staging** turns on. You can also merge from **Manage environments** or the environment bar. WP Waterfall checks for conflicts first. If a file changed on both branches, nothing changes and you get the list of files. A clean merge creates a merge commit on `master`. Staging in Git mode builds a release of it, and staging in SFTP mode pulls it into its working tree. If either side is in SFTP mode, both must have no uncommitted changes, or the merge answers 409 `working_tree_dirty`. Then deploy staging to live.

## What is on the Manage environments page?

Open the switcher and choose **Manage environments**.

- **Live and staging**: one row each with the name, address, Git branch, and who updated it last. Select a row to open it, or use its menu for **Clone content into it** and **Push this environment here**. Live shows how many commits it is behind staging only when it is behind.
- **Previews**: how many of the 5 included you used (such as **5 of 5 included**), **Create environment**, and one row per preview with its name, an **Additional** label when it is an additional one, branch, creation date, and comparison with staging ("2 ahead", "3 behind"). **Merge** appears only when the preview has commits staging lacks. A status shows only when the preview is not simply running.

## How do I copy content between environments?

Use **Push environment** on **Info**, or the **Clone database and files** card on **Manage environments**. Both copy database tables and uploads, never code. See [Copy content between environments](https://docs.wpwaterfall.com/push-environments), which also covers copying staging or a preview into live. To reset staging from live, including code, use the API or the `reset_site` tool.

## What does Environment details show?

On live, whether the CDN and edge caching are on, and the addresses a domain points at (**Point your domain at**). Every environment shows its **External IP Address**, the address other services see. Staging and previews show the CDN and edge caching as off. See [IP addresses](https://docs.wpwaterfall.com/ip-addresses).

## How do snapshots and restores work?

WP Waterfall takes a snapshot of an environment before every risky change, such as a promote, a PHP change, a search and replace, a clone, or a restore. You can also take manual ones. See [Backups](https://docs.wpwaterfall.com/backups).

## How do I delete an environment?

Choose **Delete environment** at the bottom of a preview's **Info** page, choose **Delete** on its row in **Manage environments**, or use its row menu in the switcher. Deleting keeps a snapshot of its code, database, and uploads for 30 days and keeps its Git branch, so you can create it again. Deleting an additional preview also frees its slot, and you pay only for the hours it ran. Staging and live go only with the site.

## Quick answers

**Can I deploy straight to live?**
No. Change code on staging, commit it, then deploy from live's **Deploys** card.

**Can I install a plugin on live?**
No. Install it on staging and promote. On live you can still deactivate a plugin or switch the theme.

**Do uploads on live still work?**
Yes. Nothing in a promote, rollback, or restart touches `wp-content/uploads`. See [Manage files](https://docs.wpwaterfall.com/files-manager).

**Why is my staging site slow on the first visit?**
It was asleep. See [Sleeping environments](https://docs.wpwaterfall.com/sleeping-environments).

## Related

- [Sleeping environments](https://docs.wpwaterfall.com/sleeping-environments)
- [How Git deploys work](https://docs.wpwaterfall.com/code/git-workflow)
- [wpwaterfall.yml reference](https://docs.wpwaterfall.com/code/wpwaterfall-yml)
