Skip to content

WordPress staging vs production drift: detection and reconciliation

WordPress staging environments drift from production silently — plugin versions, option values, schema. Here is how to detect WordPress drift before the next deploy surprises you.

WordPress staging environments are never identical to production after the first week. Someone updates a plugin on staging only, an editor saves an option on production, a migration runs on one but not the other. By the time you promote staging to production, six things have diverged — and one of them is going to be the production-only bug you hit at noon.

What’s happening

Drift accumulates across four dimensions: code (plugin and theme files), data (database content and options), schema (table definitions, especially custom plugin tables), and configuration (wp-config.php, environment variables, .htaccess). Most teams version-control the code via Git, which catches one dimension. The other three are mostly invisible until something breaks.

The painful drift cases: a plugin updated on production via the admin UI never made it into the staging git checkout, a custom option added by an editor on production isn’t on staging, a custom table created by a plugin update exists on one and not the other, or a WP_CACHE = true constant on production isn’t mirrored on staging so the bug doesn’t reproduce.

How to verify

# Plugin version drift:
diff <(wp --path=/var/www/staging plugin list --format=csv --fields=name,version) \
     <(wp --path=/var/www/production plugin list --format=csv --fields=name,version)

# Option drift (for a known set):
for opt in siteurl home blog_charset active_plugins; do
  echo "=== $opt ==="
  wp --path=/var/www/staging option get $opt
  wp --path=/var/www/production option get $opt
done

# Schema drift:
diff <(mysqldump --no-data -u root staging_db | sort) \
     <(mysqldump --no-data -u root prod_db | sort)

# File diff:
diff -r /var/www/staging/wp-content /var/www/production/wp-content

The fix

  1. Compare plugin and theme versions. The diff above catches version skew. If staging is on a newer version than production, you need to test the upgrade path on staging first.
  2. Use schema-only mysqldump for table drift. mysqldump --no-data gives you just the CREATE TABLE statements. Sort and diff. New tables, dropped tables, changed columns — all show up.
  3. Use wp config list for constant drift. wp config list --format=csv on both environments, diff the output. A different DB_HOST or WP_CACHE is expected; a different WP_DEBUG between staging and production is fine; a different WP_CONTENT_DIR is a real bug.
  4. Snapshot the options table. A weekly cron exports wp_options to a known location: wp db export --tables=wp_options wp_options_$(date +%Y%m%d).sql. Diff against the previous week to catch silent option changes.
  5. Use git on mu-plugins. Drop-in files in mu-plugins are easy to forget. Version-control the directory.
  6. Run a smoke test post-promotion. A 30-line script that hits the homepage, a category page, a logged-in admin page, and the REST endpoint catches 80% of drift-caused regressions.

For teams running staging-to-production promotions multiple times per week, Stack Harbor wires drift detection into enterprise WordPress support CI. To set up automated drift checks, book a consult.