Skip to content
Blog

Run WordPress locally with DDEV against a real site

How to run WordPress locally with DDEV against a real site: pull code, database, and uploads from WP Waterfall, edit, and push code back to staging.

The WP Waterfall team · Workflow

This post is for developers who want to run WordPress locally with DDEV against a real site, with the exact commands and the reasons behind them. DDEV is a Docker based local environment for PHP projects. Our DDEV add-on links a DDEV project to one WP Waterfall environment and moves code, database, and uploads in whichever direction is safe.

What moves, and which way

  • Code moves with Git. Pull and push for staging and previews, and pull only for live.
  • The database moves over SSH or from a backup. Pull and push for staging and previews, and pull only for live, from a backup.
  • Uploads move the same way as the database.

Live is pull only. You can copy production down to reproduce a bug, and you can never push anything back to it. Changes reach live by a push to staging and a promote, the same as every other change on the platform.

The local copy pulls from any environment and pushes only to staging or a preview.

Setup

You need Docker, DDEV 1.25 or newer, an SSH key on your account, and an API key with sites:read, sites:write, and backups:write. On Windows, Docker and DDEV run inside WSL2 with Ubuntu.

The quickest start is the starter zip from the Local development card on the site's Info tab, then bash setup.sh. Without the starter, in an empty folder with a DDEV project:

ddev add-on get https://get.wpwaterfall.com/local.tar.gz
ddev wpwaterfall setup my-site        # staging
ddev wpwaterfall setup my-site qa     # the preview named qa

Setup checks the machine, frees ports 80 and 443, makes your browser trust DDEV's certificate, asks for the API key with hidden input, finds or makes an SSH key, links the site, and pulls. It stops at the first step that cannot work and prints the fix.

The API key never lands in a project file. The add-on reads WPWATERFALL_API_KEY from the shell, or runs WPWATERFALL_API_KEY_COMMAND (for example pass show wpwaterfall), or reads ~/.config/wpwaterfall/api-key with mode 600, or prompts. Keep it that way: a key in .ddev/ ends up in Git.

The everyday loop

ddev wpwaterfall pull --all              # first time: code, database, uploads
ddev wpwaterfall login --launch          # open wp-admin as the local admin
# edit, then test at https://my-site.ddev.site
git commit -am "Tighten the checkout form"
ddev wpwaterfall push --code             # push to staging; the platform builds it

pull --code clones the repository the first time, so wp-content is the working tree, and runs git pull --ff-only after that. It never discards your work: a diverged branch stops the pull, and --rebase is explicit. Code is plain Git, so git push wpwaterfall master works too. Staging is master, and a preview is its own branch name.

A push to the environment's branch builds a new release on staging.

A database pull rewrites the site address to your local https:// one in every table, serialized values included, keeps your table prefix, and turns off mail and backup plugins that hold live credentials. It also creates a throwaway administrator, wpwaterfall-local, because the real users' passwords are unknown to you. The password sits in .ddev/wpwaterfall-local-login with mode 600 and is removed before any database push.

Match the server, not your laptop

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 moves to a new PHP version, the next ddev start follows. To try another version before the server does:

ddev wpwaterfall php            # the server's version, yours, and the choices
ddev wpwaterfall php 8.3        # switch locally and restart
ddev wpwaterfall php --server   # back to the server's version

That changes nothing on the server. The point is that "works on my machine" and "works on staging" mean the same PHP.

Pull production data with care

ddev wpwaterfall pull --db --from live --sanitize

--from live takes the database from a backup, because live has no SSH into its code. --sanitize masks user emails, resets passwords, and clears comment author data in the local copy only. Add --sanitize-profile full to also clear WooCommerce customers and orders. We built that flag because the easy path, a raw copy of production on a laptop, is how customer data leaks.

A push of the database or uploads replaces what staging has, so the add-on takes a backup first and asks you to confirm. --tables wp_posts,wp_postmeta limits a push to the tables you changed.

When it breaks

ddev wpwaterfall doctor checks the machine, the project, and the connection, and --fix applies what it can. ddev wpwaterfall update updates the add-on, and it keeps itself current. The reference, including Windows and the certificate, is in Develop locally with DDEV.

What to do next

Run setup against staging, make one small change, and push it. After the first loop, every one after it is a commit and a push.

Read next

Try what you just read about.

See it in your own dashboard.