# Develop locally with DDEV

> Run a copy of a WP Waterfall environment on your computer with DDEV. Code moves with Git, the database and uploads with the add-on. Live is read only.

Source: https://docs.wpwaterfall.com/develop-locally-with-ddev

The WP Waterfall DDEV add-on makes a working copy of an environment on your computer: the code from Git, plus the database and uploads. You edit in your own editor and see the site at `https://NAME.ddev.site`. You choose what moves each time.

| Part | How it moves | Staging and previews | Live |
|---|---|---|---|
| Code | Git, through the WP Waterfall remote | Pull and push | Pull only |
| Database | SSH, or a backup download | Pull and push | Pull only, from a backup |
| Uploads | SSH, or a backup download | Pull and push | Pull only, from a backup |

You can copy live down but never send anything back to it. To change live, push to staging and promote.

## What do I need?

- **Docker and DDEV 1.25 or newer.** On Windows, both go inside WSL2 and Ubuntu. On Linux, Docker Engine. macOS is untested; see [the limits](#what-are-the-requirements-and-limits).
- **An SSH key on your WP Waterfall account.** See [Git access](https://docs.wpwaterfall.com/git-access#how-do-i-add-an-ssh-key-to-my-account).
- **An API key** with `sites:read`, `sites:write`, and `backups:write`, made under **Account settings**, **Integrations**, **API keys**. Code and an SSH pull need only `sites:read`. Live data and database pushes use a backup, which needs `backups:write`. See [API keys and scopes](https://docs.wpwaterfall.com/api-keys-and-scopes).
- **On your computer:** `bash`, `curl`, `jq`, `git`, `tar`, and `gzip`. Setup lists what is missing.

The API key never goes into a project file. The add-on looks for it in this order: `WPWATERFALL_API_KEY` in your shell, the command in `WPWATERFALL_API_KEY_COMMAND` (for a keychain, such as `pass show wpwaterfall`), the file `~/.config/wpwaterfall/api-key` (mode 600), then a hidden prompt.

## How do I set it up?

1. On the **Info** tab of your site, in the **Local development** card, choose **Download starter** and unzip it into a folder.
2. Open a terminal there and run `bash setup.sh` (macOS and Linux) or `powershell -ExecutionPolicy Bypass -File .\setup.ps1` (Windows, which needs WSL2 with Ubuntu; see [Local development on Windows with WSL2](https://docs.wpwaterfall.com/local-development-windows-wsl2)).
3. Answer the questions. Setup asks before it changes anything.

The starter holds the DDEV settings for that environment, a README, and the two setup scripts. It holds a host, a port, and a user name, never a password or a key.

You can skip the starter. In an empty folder with a DDEV project, run:

```bash
ddev add-on get https://get.wpwaterfall.com/local.tar.gz
ddev wpwaterfall setup my-site
```

Add an environment name for a preview or live, such as `ddev wpwaterfall setup my-site qa`. The add-on keeps itself up to date (see [Keep the add-on up to date](#keep-the-add-on-up-to-date)), and `ddev add-on remove wpwaterfall` removes it.

### What does setup do?

It goes through seven steps and stops at the first one that cannot work, with the exact fix.

1. **Checks the computer:** the system, the tools above, and that Docker answers. It installs nothing.
2. **Ports 80 and 443,** which DDEV uses so the address has no port. If a program holds one, setup names it and prints the command to stop it. See [Port is already allocated](https://docs.wpwaterfall.com/local-development-troubleshooting#port-is-already-allocated).
3. **Browser trust.** The local site opens over https only, so setup makes your browser trust DDEV's certificate. If the browser still warns, see [the certificate fix](https://docs.wpwaterfall.com/local-development-troubleshooting#your-browser-says-the-connection-is-not-private).
4. **Your API key,** asked with hidden input and checked with WP Waterfall.
5. **An SSH key:** the one you name with `--ssh-key`, or one from `~/.ssh`. With none, it offers to make `~/.ssh/wpwaterfall_ed25519` and prints the public half to add under **Account settings**, **Integrations**, **SSH keys**.
6. **Links the site,** writes the DDEV files, adds the Git remote, and starts DDEV.
7. **Pulls** code, database, and uploads, rewrites addresses to your local one, and makes a local admin login.

### What is the local admin login?

A pulled database has real users whose passwords you do not know. So the first database pull makes a throwaway administrator, `wpwaterfall-local`, that exists only locally. Its random password is shown once and kept in `.ddev/wpwaterfall-local-login` (mode 600, never in Git). Show it again, or open wp-admin, with `ddev wpwaterfall login` (add `--launch` to open the browser). Before a database push the add-on removes that user. `ddev wpwaterfall login --create` makes it again, and `--no-local-admin` on a pull skips it.

## How do I get my API key?

Setup needs an API key to link the site and read its settings. If it finds none, it stops before it changes anything and shows these steps:

1. Open [my.wpwaterfall.com](https://my.wpwaterfall.com/dashboard), then **Account settings**, **Integrations**, **API keys**, then **Create key**. Tick `sites:read`, `sites:write`, and `backups:write`, and choose a 30 day expiry. The key is shown once, so copy it then.
2. Give it to setup in one of three safe ways:
   - **Hidden prompt:** run `ddev wpwaterfall setup` in a terminal and paste the key. Nothing shows on screen. Setup offers to keep it in `~/.config/wpwaterfall/api-key`, a file only you can read, outside every project.
   - **Shell variable,** for `--yes` and for an AI assistant: `export WPWATERFALL_API_KEY=<your key>` in the shell, then run setup. Setup never writes a key it got this way to a file.
   - **Keychain:** set `WPWATERFALL_API_KEY_COMMAND` to a command that prints the key, such as `secret-tool lookup service wpwaterfall` or `security find-generic-password -s wpwaterfall -w`.
3. Check it with `ddev wpwaterfall doctor`.

Never put the key on a command line, in a file in your project, or in a chat with an assistant. Setup refuses `--api-key` for that reason.

No key yet? Code and the staging database work with an SSH key and Git alone. Add the public key under **Account settings**, **SSH keys**, then use `git pull` and `git push` with the `wpwaterfall` remote. You still need the key to link a site, read its settings, pull from live, and push the database or uploads.

Doctor and setup tell the cause in one or two sentences when something is wrong: no key, a key that lacks a scope (it names the scope), a key that was mistyped, has expired, or was revoked, an SSH key that is not on your account, ports 80 and 443 in use, or Docker not running.

## Can my AI assistant set it up?

Yes, if it is connected to WP Waterfall and can run commands on your computer. You never paste a key. Say:

> Set up WP Waterfall local development with DDEV for my site NAME. Use the set_up_local_development prompt.

Add "preview QA" or "live" for a copy of that environment instead of staging. The assistant checks `ddev` and `docker`, tells you in one sentence what will be copied, installs the add-on, makes an API key with only `sites:read`, `sites:write`, and `backups:write` that expires in 30 days (and an SSH key if none exists), runs `ddev wpwaterfall setup` with the key in `WPWATERFALL_API_KEY` for that one command, and finishes with `ddev wpwaterfall doctor`. Each key step asks you first. See [MCP connections](https://docs.wpwaterfall.com/mcp/tools-and-guardrails#what-can-an-assistant-do-with-api-keys-and-ssh-keys). Revoke the connection or the key when you are done.

With `--yes`, setup asks nothing and prints each choice. It reads the API key only from `WPWATERFALL_API_KEY`, because a key on a command line shows in the process list. A key with a passphrase cannot be used when nobody can type it. With no SSH key, setup makes one and stops before the pull until you add its public half to your account. Other flags: `--no-pull`, `--no-local-admin`, `--skip-trust`, and `--custom-ports`.

## How do I add a plugin or change code?

Edit and commit locally, push to staging with `git push wpwaterfall master`, check the result, then promote. The whole flow is in [How Git deploys work](https://docs.wpwaterfall.com/code/git-workflow). WP-CLI cannot activate a plugin on live, so add the command to `deploy.hooks` in `wpwaterfall.yml` (for example `plugin activate my-plugin`) and push it with the plugin. A database or uploads change reaches live only through [Copy staging into live](https://docs.wpwaterfall.com/push-environments).

## Which platform notes apply?

- **Windows:** use WSL2 with Ubuntu and keep the project in the Linux home folder, never under `C:\`.
- **macOS:** Docker Desktop, OrbStack, or Colima, with at least 4 GB of memory. For a large site, try Mutagen: `ddev config --performance-mode=mutagen`, then `ddev restart`.
- **Linux:** put your user in the `docker` group (`sudo usermod -aG docker $USER`) and open a new terminal.

The browser certificate and ports 80 and 443 are covered in [Troubleshoot local development](https://docs.wpwaterfall.com/local-development-troubleshooting).

## How do PHP and database versions match the server?

`init` reads the environment's PHP version and picks the nearest MariaDB version DDEV offers, and writes both to `.ddev/config.wpwaterfall.yaml`. When the server's PHP version changes, the next `ddev start` applies it. A new database version is only reported, with the command that switches it.

To try another PHP version locally:

```bash
ddev wpwaterfall php           # shows the server's version, yours, and the choices (7.4 to 8.5)
ddev wpwaterfall php 8.3       # switch and restart DDEV
ddev wpwaterfall php --server  # go back to the server's version
```

This does not change the server. If DDEV refuses to start with `its database volume holds mariadb:11.8`, see [the fix](https://docs.wpwaterfall.com/local-development-troubleshooting#the-project-will-not-start-its-database-volume-holds-mariadb118).

## What is the everyday flow?

1. **Pull** what you need: `ddev wpwaterfall pull --all` the first time.
2. **Edit** the code. The project folder is a normal Git repository.
3. **Test** at `https://NAME.ddev.site`, log in with `ddev wpwaterfall login`, and read mail in Mailpit (`ddev launch -m`).
4. **Commit,** then `ddev wpwaterfall push --code` to staging. The platform builds it.
5. **Test on staging,** then promote staging to live in the dashboard.

`pull` and `push` take `--code`, `--db`, `--uploads`, or `--all`, in any mix. With no flag in a terminal, the add-on asks. A pull starts with all three ticked and a push with code only. In a script you must pass a flag.

```bash
ddev wpwaterfall pull --db --uploads               # fresh data, keep your code (this replaces your local database)
ddev wpwaterfall pull --db --uploads --from live   # reproduce a bug with production data, from a backup
ddev wpwaterfall push --code                       # send your commits to staging
```

What a pull brings, and what it leaves alone, is in [Pull code, a database, and uploads](https://docs.wpwaterfall.com/pull-a-database-and-files). Pushing data, or only some tables, is in [Push a database or uploads to staging](https://docs.wpwaterfall.com/push-code-to-staging). Code moves by plain Git: see [Git access](https://docs.wpwaterfall.com/git-access).

## Keep the add-on up to date

Each `ddev start` and `ddev restart` checks for a newer add-on and for new settings from WP Waterfall, and applies them. You see one line in the start output, such as `WP Waterfall: Updated: add-on 0.5.0 to 0.5.1; PHP 8.3 to 8.4; restarted.` or `WP Waterfall: Up to date (add-on 0.5.0).` A check takes a second or two.

- **Offline,** the start prints `WP Waterfall: offline, update check skipped.` and goes on.
- **If an update fails,** the start still goes on, and one line says what failed and to run `ddev wpwaterfall update`.
- **A new add-on** is downloaded over https, and its signature is checked with `openssl` before anything is unpacked or installed. WP Waterfall signs every release, and the add-on carries the public key. If the signature is missing or wrong, or your computer has no working `openssl`, nothing is installed, the add-on you have stays, and one line says why. It never goes back to an older version. An add-on older than 0.6.0 cannot check signatures, so it takes 0.6.0 by its checksum, and every update after that is checked.
- **New settings** it applies by itself: the PHP version (unless you chose one with `ddev wpwaterfall php`), the SSH address and host key, the Git remote, and the web root. When one of them needs it, DDEV restarts once.

Run it by hand any time:

```bash
ddev wpwaterfall update          # this project
ddev wpwaterfall update --check  # only show what would change
ddev wpwaterfall update --all    # every DDEV project on this computer that has the add-on
```

A run by hand asks before it restarts DDEV, and `--yes` restarts without asking. `--all` prints one line per project and never starts a stopped project. It also updates projects on an add-on from before this command existed.

It never touches your database, code, or uploads, and it never changes these by itself. It prints the command instead:

- **New subsites on a network:** `ddev wpwaterfall pull --db`. The [address map](https://docs.wpwaterfall.com/local-development-with-multisite#the-address-map) changes only with a database pull.
- **A single site that became a network, or a new network type:** `ddev wpwaterfall init --refresh`, then `ddev wpwaterfall pull --db`.
- **A new database engine or version:** `ddev wpwaterfall init --refresh`, which offers to switch the database and snapshots one with tables first.
- **A new table prefix:** a database pull uses the server's real prefix, and `ddev wpwaterfall init --refresh` records the new one.

To turn the update on start off, set `WPWATERFALL_AUTO_UPDATE=off` in your shell. It is also off when `CI` is true and when you installed the add-on from a folder on your computer. `ddev wpwaterfall doctor` says whether it is on.

## What are the commands?

Run `ddev wpwaterfall --help` for the same list.

| Command | What it does |
|---|---|
| `setup [SITE [ENVIRONMENT]]` | The whole setup above. Flags: `--yes`, `--ssh-key PATH`, `--no-pull`, `--custom-ports`, `--skip-trust`, `--no-local-admin`. |
| `init [SITE [ENVIRONMENT]]` | Link the project to an environment and write settings. With no site it lists your sites. Flags: `--refresh`, `--api-url URL`, `--yes`. |
| `pull` | Copy parts down. Flags: `--code`, `--db`, `--uploads`, `--all`, `--from ENV`, `--method ssh\|backup`, `--fresh-backup`, `--rebase`, `--disable-dropins`, `--max-size 50M`, `--uploads-days N`, `--bwlimit 5M`, `--no-local-admin`, `--sanitize`, `--sanitize-profile minimal\|full`. |
| `push` | Send parts to staging or a preview. Flags: `--code`, `--db`, `--uploads`, `--all`, `--to ENV`, `--yes`, `--max-size 50M`, `--bwlimit 5M`, `--tables LIST`, `--allow-sensitive`. |
| `code` | Follow the environment's branch. `--release live` checks out live's commit. `--rebase` rebases your commits. |
| `login` | Show the local admin login. `--launch` opens wp-admin, `--create` makes the login if missing. |
| `php` | Show or switch the local PHP version. |
| `trust` | Make the browser trust DDEV's certificate. `--check` only reports. |
| `status` | What the project is linked to, and whether WP Waterfall's settings changed. |
| `doctor` | Check the computer, connection, and site. Flags: `--login`, `--fix`, `--yes`, `--custom-ports`. |
| `exclude list\|add PATTERN\|remove PATTERN` | Your own upload patterns to skip. |
| `update` | Install a newer add-on and apply new settings. It also runs on every start. Flags: `--check`, `--yes`, `--all`. |
| `version` | The add-on version. |

Exit codes: 0 done, 1 a step failed, 2 usage, 3 not signed in, 4 refused, 5 a transfer or check failed, 6 not found. DDEV prints `error=exit status N` and exits 1 for a failed host command, where N is the add-on's code.

## What are the requirements and limits?

- WP Waterfall serves the add-on from `https://get.wpwaterfall.com/local.tar.gz`, not the DDEV registry, so `ddev add-on update` skips it and `ddev wpwaterfall update` does the job. To pin a version, use a file such as `local-0.6.0.tar.gz` from the same address and set `WPWATERFALL_AUTO_UPDATE=off`. Its SHA-256 is next to it with `.sha256` on the end, and its signature with `.sig`. Only the newest version stays on the server: keep the file you downloaded if you pin one.
- The add-on is tested on Linux and on Windows with WSL2 (Docker Engine). Docker Desktop, macOS, and arm64 Linux are untested. Windows without WSL2 and Local by WP Engine are not supported.
- When WP Waterfall reports no SSH host key fingerprint, the first connection trusts the host and pins it from then on.

## API

- `GET /v1/environments/{id}/local-dev`: the settings the add-on reads. It holds no secret.
- `POST /v1/environments/{id}/local-dev/pull-session` and `.../push-session`: record a pull or push in the activity log and return the plan.
- `POST /v1/environments/{id}/backups`, `POST /v1/backups/{id}/download`, and `POST /v1/backups/{id}/download-link`: how live data reaches your computer.

The MCP server offers `get_local_dev_config` (read only) and the prompt `set_up_local_development`. On a connection you approved, `create_api_key`, `list_api_keys`, `revoke_api_key`, `list_ssh_keys`, `add_ssh_key`, and `remove_ssh_key` do the key steps, each in two steps.
