Skip to content

WordPress staging to production: what moves, what never moves, and how the database is merged

This guide walks you through a WordPress staging to production promotion, so the release goes live without erasing the orders, accounts and comments your live site recorded while you worked. You will also learn what a WP Engine or cPanel push button actually overwrites.

This guide walks you through promoting a WordPress site from staging (your private test copy) to production (the live site your visitors use). The hard part is the database, because production keeps recording orders, accounts and comments the whole time you work on staging, and importing staging’s database would erase every one of them. The safe rule is that code and configuration move forward, content and uploads come back, and the database moves row by row rather than all at once. You will see both paths here, the host push button in WP Engine or cPanel and a manual promotion with WP-CLI (the WordPress command line) and Git. By the end you have a restore point taken before the one irreversible step, and checks that prove the live site is still whole.

What you’ll accomplish

  • Staging refreshed from production on a schedule, so tests run against real data volume rather than a stale snapshot.
  • A written rule for every category of data: forward, backward, or neither — and inside the database, a rule per table rather than one for the whole dump.
  • A promotion you can rehearse freely, with exactly one irreversible step in it.
  • A restore point before that step, a rollback you can execute, and an honest sense of what it costs.
  • An end-to-end check that proves the promotion landed, rather than a homepage that loads.

Prerequisites

You need SSH access to both environments, WP-CLI 2.x on both ends, and the same PHP major version in staging and production. WP Engine’s SSH is a gateway scoped to WP-CLI, rsync and git rather than a full shell, which is enough for everything below. On cPanel, wp is usually on the path; check with wp --info.

Two assumptions matter. First, staging is not the source of truth for content: if editors draft posts there expecting them to appear live, you have a second production rather than a staging environment, and the workflow below will lose their work. Second, staging must be blocked from search engines and from real outbound mail before it holds a copy of production.

How it works

A WordPress install is not one artifact. It is code you wrote, configuration that differs per environment, content people created, binary uploads, and derived state valid only for the machine that made it. A promotion goes wrong when a tool treats all five as one blob.

Diagram of the two promotion directions: code and config moving from staging to production, content and uploads moving back, with the set of data that must travel in neither direction called out

Forward, staging to production. Theme and plugin code, wp-config.php constants belonging to the release, and schema migrations — as files and version-controlled scripts, never as a database dump.

Backward, production to staging. The database and the uploads/ directory. Real content is what makes a staging test meaningful: a query that is fast against 40 posts can time out against 40,000, and a layout that survives clean sample data breaks on the one post pasted from Word in 2019.

Neither direction. This is the set most teams miss, and every item on it has burned somebody:

  • Serialized URLs. Widget settings, theme mods and page-builder layouts are stored as PHP-serialized strings with byte-length prefixes. A find-and-replace over a SQL dump changes the string but not the prefix, and the value silently deserializes to nothing. Use wp search-replace, which walks the structure properly.
  • Transients and object-cache state. Fragments keyed to the old URL, or to a plugin version you just replaced, outlive the promotion and serve stale markup.
  • SMTP, payment and API credentials. A database copied down to staging carries live Stripe and SMTP keys, and the next test order charges a real card.
  • Search indexes and cron locks. Elasticsearch and Relevanssi point at post IDs in one database, so a copy without a reindex returns posts that are gone; and a copied doing_cron row stalls scheduled events until it expires.

The rule that follows: a promotion moves code forward and then rebuilds derived state on the target. It never copies derived state anywhere.

The database does not copy, and it does not merge

Files have one writer: you. The database has two — you on staging, and everyone using the live site, continuously, for the whole staging window. Nothing in WordPress or in any host control panel reconciles those two histories. Importing staging’s database into production is not a merge, it is a replacement: every order, account, comment and form entry production recorded since the last refresh disappears with it. On a store, those rows are the business.

So the question is never “should I push the database”. It is “which rows does this release own, and how few of them can I move”.

Diagram classifying WordPress and WooCommerce database tables into three groups: tables that must never be overwritten from staging, the options table which moves only row by row, and the small set of release-owned tables safe to push whole

Never travels forward. Anything customers or editors write. On a WooCommerce store using High-Performance Order Storage that is wp_wc_orders, wp_wc_orders_meta, wp_wc_order_addresses and wp_wc_order_operational_data; on the older storage the same orders live as shop_order rows in wp_posts and wp_postmeta. Line items sit in wp_woocommerce_order_items and wp_woocommerce_order_itemmeta either way. Add wp_users, wp_usermeta, wp_comments, wp_commentmeta, wp_woocommerce_sessions (live carts), the wp_actionscheduler_* tables holding a job queue keyed to production’s row IDs, and whichever table your form plugin writes into. Prefixes vary; get the real list with wp db tables --all-tables-with-prefix.

Moves row by row, never as a table. wp_options does two unrelated jobs. Some rows are release configuration: permalink_structure, the woocommerce_* settings a release changes, theme mods, the page IDs a plugin points at. The rest is live state belonging to whichever machine generated it: _transient_*, doing_cron, sessions, API credentials. There is no table-level answer, only an option-name-level one, which is why the promotion below pushes options by name.

Safe to push whole. A very short list: a table the release creates and production never writes to, such as a lookup table your code populates from a build step. If you cannot name the code that writes to a table, assume production does.

What a platform push button actually does

Managed platforms give you a copy tool, not a merge tool, and that distinction is the whole article. WP Engine’s Copy Environment takes a source environment and a destination and copies the file system, the database, or both. Whatever you select overwrites the destination, and the tool rewrites the site URLs so the destination works on its own domain — the same work wp search-replace does by hand, and the one merge-shaped thing the button does. It does not compare rows, preserve writes the destination made while you worked, know which of your plugin options are environment-specific, or promise anything about a CDN you run in front of it. Undoing a copy is a separate action, from a backup point you took beforehand.

cPanel’s WordPress Toolkit models the same operation as a data copy between a clone and its source, separating files from databases; if your version offers a table selection there, it moves the “which tables” decision into the interface but still overwrites the tables you pick. The cPanel staging promotion walkthrough covers that interface step by step.

The safe default does not depend on which buttons you have: files forward, database not.

Step-by-step

Steps 1 to 4 are rehearsal and preparation. Step 5 onward is live.

Diagram of the four-stage promotion window showing what happens at each stage, what a rollback costs, and what must never travel at that step

  1. Name both ends once, in wp-cli.yml. Aliases keep commands short and make it much harder to run a destructive one against the wrong environment. Put this file in the project root, or in ~/.wp-cli/config.yml to apply it everywhere:

    @prod:
      ssh: deploy@prod.example.com/var/www/example.com
    @staging:
      ssh: deploy@staging.example.com/var/www/staging.example.com

    Then check that each alias reaches the environment you think it does:

    wp cli alias list
    wp @prod option get siteurl
    wp @staging option get siteurl

    Each should print exactly one URL, and they must differ. If both print the production domain, staging points at the live database — stop here, because every command below would hit production.

  2. Refresh staging from production. Pull the database down, then the uploads.

    wp @prod db export - | wp @staging db import -
    wp @staging search-replace 'https://example.com' 'https://staging.example.com' --all-tables --precise --report-changed-only

    db import ends with a Success: Imported from line, and search-replace prints changed rows per table plus a final Success: line with a replacement count. A count of zero means the search string does not match the database — check wp @prod option get home for the exact form, www and scheme included. Then the files:

    rsync -avz --delete deploy@prod:/var/www/example.com/wp-content/uploads/ /var/www/staging.example.com/wp-content/uploads/

    rsync ends with a transferred-bytes summary; a second run should report almost nothing new.

  3. Reset everything that must not travel — on staging, immediately after the copy. Do this in the same script as step 2 so it can never be forgotten.

    wp @staging option update blog_public 0
    wp @staging option update admin_email 'staging@agency.example'
    wp @staging plugin deactivate woocommerce-gateway-stripe wp-mail-smtp
    wp @staging transient delete --all
    wp @staging cache flush
    wp @staging db query "DELETE FROM wp_options WHERE option_name = 'doing_cron';"

    blog_public should read back as 0, and transient delete --all reports how many were deleted. cache flush prints Success: The cache was flushed. when an object cache is present and a notice that none is in use otherwise — both are fine. Confirm the prefix before running the db query. If this step is ever skipped, rotate the SMTP and payment keys rather than assuming nothing went out.

  4. Do the work on staging, and list what the release changes outside of files. Check out and buy something. Submit the contact form. Load the ten heaviest pages — a release tested only on the homepage has not been tested. Alongside that, write down every option name you changed in an admin screen and every table your code created. That list is what step 9 replays on production, and if you cannot write it down, nobody can promote it safely.

  5. Take stock of what production wrote while you worked. These numbers are the reconciliation baseline and the rollback bill. Run them just before promoting:

    wp @prod db query "SELECT COUNT(*) FROM wp_wc_orders;"
    wp @prod user list --format=count
    wp @prod comment count
    wp @prod post list --post_type=any --post_status=any --orderby=modified --order=DESC --fields=ID,post_type,post_title,post_modified --format=csv | head -20

    The db query prints a column header and a single number; on the older order storage use wp @prod post list --post_type=shop_order --post_status=any --format=count instead. user list --format=count prints one integer, comment count a small table of approved, spam, trash and total counts, and the last command a CSV header plus the twenty most recently modified items. Read that last list: edits made on production during the staging window exist only there, and post content has no automatic merge — redo them afterwards, or leave those pages alone.

  6. Take a restore point, and know what restoring costs. This makes everything after it survivable, and it takes under a minute.

    wp @prod db export ~/pre-promotion-$(date +%Y%m%d-%H%M).sql
    tail -c 200 ~/pre-promotion-*.sql

    db export prints Success: Exported to ..., and the tail should end on a complete SQL statement — a dump cut off mid-INSERT restores as a partial database. On WP Engine, create a backup point in the portal at the same moment. The restore is one command:

    wp @prod db import ~/pre-promotion-20260830-1412.sql

    It prints a Success: Imported from line — and erases every order, account and comment recorded after the export. That is the honest cost: the restore window is short and shrinks as traffic rises. Promote when the store is quiet, and when a failure is configuration only, fix the option rather than restoring the database.

  7. Promote the code — the host-button path. In WP Engine’s Copy Environment, choose staging as source and production as destination, and select file system only — not the database, not “all”. Same rule for cPanel’s WordPress Toolkit: push files, not data. The host reports the copy as complete; that says nothing about whether the site works.

  8. Promote the code — the Git path. If code is version-controlled, the promotion is a merge and a deploy, not a file copy:

    git checkout main && git merge --no-ff release/2.5.0
    git tag -a v2.5.0 -m 'Promotion 2026-08-30' && git push origin main --tags

    git push reports the new ref and the tag; your pipeline takes over, and deployment automation with GitHub Actions covers building it. This path beats the button: the artifact that lands on production is the one you tested, not whatever was sitting in staging’s file system.

  9. Push only the configuration rows the release changed. This is the selective database push, deliberately narrow. Start by seeing the difference rather than guessing:

    wp @staging option list --search='woocommerce_*' --fields=option_name,option_value --format=csv | sort > /tmp/staging-wc.csv
    wp @prod option list --search='woocommerce_*' --fields=option_name,option_value --format=csv | sort > /tmp/prod-wc.csv
    diff /tmp/prod-wc.csv /tmp/staging-wc.csv

    diff prints only the option rows that differ. Most are environment-specific and should stay put; page-ID options such as woocommerce_shop_page_id point at post IDs that differ between the databases, so copying one sends production to a page that does not exist. Move the handful that belong to the release, one at a time, in JSON so serialized arrays survive:

    wp @staging option get woocommerce_tax_display_cart --format=json
    wp @staging option get woocommerce_tax_display_cart --format=json | wp @prod option update woocommerce_tax_display_cart --format=json

    The first prints the value as JSON so you can read it before sending it. The second prints Success: Updated 'woocommerce_tax_display_cart' option., or a Success: line saying the value is unchanged when production already matched. For a table the release created and production never writes to, a whole-table push is fair:

    wp @staging db export - --tables=wp_acme_shipping_rules | wp @prod db import -

    The export carries a DROP TABLE IF EXISTS, so it replaces the table rather than merging into it — exactly why the rule is “release-owned tables only”. The WP-CLI db export reference documents --tables and its inverse --exclude_tables.

  10. Run schema changes once, on production, as a script. If the release adds a custom table or column, that change is code, and it belongs in the repository:

    wp @prod eval-file ./migrations/2026-08-add-event-table.php
    wp @prod core update-db

    Migration scripts must be idempotent, because someday one will run twice. core update-db prints Success: WordPress database upgraded successfully or reports the database is already current; either is a pass.

  11. Rebuild the derived state on production. The new code invalidates caches the old code populated.

    wp @prod transient delete --all
    wp @prod cache flush
    wp @prod rewrite flush --hard

    rewrite flush prints Success: Rewrite rules flushed. Then purge the page cache and the CDN from their own dashboards — WP-CLI does not reach an edge cache, and until you purge, anonymous visitors still get the old markup. Reindex search as well.

Validate it works

Start with the counts from step 5, because the failure that matters most is silent:

wp @prod db query "SELECT COUNT(*) FROM wp_wc_orders;"
wp @prod user list --format=count
wp @prod comment count

Every number must equal or exceed what you recorded before the promotion. A number that went down means a staging database crossed the line: restore from step 6 immediately rather than investigating, because every minute spent reading logs is another order written on top of the wrong data.

Then confirm the code and configuration landed:

wp @prod option get siteurl && wp @prod option get home
wp @prod core verify-checksums
wp @prod plugin list --status=active --fields=name,version --format=csv

siteurl and home must be the production domain — if either shows the staging hostname, a database crossed the line. verify-checksums should report success. Run the same plugin list against @staging and compare: it should differ only by plugins you deliberately keep off staging, and anything else means the file copy was partial.

Then the outside view and the scheduled work:

curl -sI https://example.com/ | head -20
wp @prod cron event list --fields=hook,next_run_relative | head -20

You want a 200, a cache header from whichever page cache you run, and no X-Robots-Tag: noindex — that header on production is the classic sign a staging database or wp-config.php came forward. Cron events should show sane next-run times, not overdue entries.

Finally, exercise the site as a human — a real checkout, a password reset, a contact form — and watch the error log for fifteen minutes.

Troubleshooting

Orders, customers or comments are missing after the promotion. A database went forward — a “copy everything” in the host tool, or a full wp db import against production. Those rows are not damaged, they are gone, and nothing inside WordPress recovers them, because they never existed on staging. Restore the dump from step 6, or the platform backup point from the same moment, and accept losing whatever was written between that point and the moment you noticed. Compare the step 5 counts against the restored database to state the size of the gap, then re-promote with files only.

Widgets, theme options or page-builder layouts came back empty. Something replaced URLs with SQL rather than wp search-replace, breaking the byte-length prefixes in serialized values. A broken serialized string cannot be repaired; restore the database and redo the replacement with wp search-replace --precise. The WP-CLI command reference documents the flags.

Production is serving staging URLs, or noindex appeared on the live site. The database or wp-config.php travelled forward. Restore the dump from step 6, re-promote with files only, then set blog_public back to 1 and request re-indexing — a live site left on noindex for a week is an SEO incident, not a cosmetic one.

The promotion looks live over SSH but visitors see the old site. A page cache or CDN still holds the previous render. Purge both from their dashboards. On WP Engine the page cache sits in front of PHP entirely, so nothing run inside WordPress clears it.

Scheduled posts, emails and background jobs stopped. Either a doing_cron lock came across in a database copy, the wp_actionscheduler_* tables were overwritten with staging’s queue, or WP-Cron is disabled on the target with no system cron replacing it. Delete the lock row, check wp @prod cron event list again, and look at the WooCommerce scheduled-actions screen for jobs stuck as pending with past dates.

When this is the wrong approach

If editors author content on staging and expect it to appear live, this shape does not fit. That is a content-staging problem, solved by drafts and scheduled publishing on production — not by promoting a database. And if the release is a single plugin update on a low-traffic brochure site, a full staging cycle costs more than it returns: take a backup, update in place, check the pages that matter.

If the release takes weeks while production takes orders, no recipe rescues it: the divergence outgrows any reconciliation you can do by hand. Shorten the window into days, move configuration into code, or ship in smaller pieces.

If staging and production differ in PHP version, database engine or web server, staging is not predictive; fix the parity first. And promoting between hosts rather than between environments is a migration with its own order of operations, not a promotion.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.