Key points
- A staging site is a private copy of your website where updates and changes are tested before they touch the live site.
- It needs password protection, must stay out of Google, and must not be able to send real emails or take real payments.
- Golden rule: code moves up from staging to production, data moves down from production to staging, never the other way.
“We updated the plugin and now the contact form is broken.” On a site that brings in leads or sales, that kind of discovery is expensive, especially at six o’clock on a Friday. The fix is well known but still rare on small business sites: a staging site that mirrors the live one, where everything gets tested before it goes anywhere near production. We set one up on most of the sites we maintain, brochure sites included. Here’s how, along with the safeguards you can’t skip.
What staging is for (and what it isn’t)
A staging site is a full copy of your site (files, database and configuration) running at a different address, usually a subdomain like staging.example.com, and accessible only to your team. You use it to:
- test WordPress core, theme and plugin updates before applying them to the public site;
- build a new page, template or feature and get the client to sign it off;
- reproduce a reported bug without risking making things worse on the live site;
- prepare a PHP version upgrade by checking everything works on the new version.
It’s neither a backup nor a local development environment: it’s where you validate under conditions close to the real server (same PHP version, configuration and caching).
Across our maintenance contracts, most incidents we’ve avoided were caught because an update broke something on staging first.
Creating the copy with WP-CLI
Plenty of hosts offer a “create staging” button. If you use it, check that the “push to live” button does not send the database too, and that the copy is password-protected. Otherwise, WP-CLI does the job. You’ll need a subdomain pointing at its own folder, an empty database with its own user, and an SSL certificate for the subdomain.
# From the production site's folder, on the same server
wp db export ~/prod.sql
rsync -a --exclude='wp-content/cache/' ./ ../staging/
cd ../staging
# BEFORE importing: point the copy at its own database
wp config set DB_NAME example_staging
wp config set DB_USER example_staging
wp config set DB_PASSWORD 'dedicated-password'
wp config set WP_ENVIRONMENT_TYPE staging
wp db import ~/prod.sql
wp search-replace 'https://www.example.com' 'https://staging.example.com'
--all-tables --precise --skip-columns=guid
wp option update blog_public 0
wp cache flush
rm ~/prod.sql
Three things deserve attention. First, the order: the configuration must point at the new database before you import, otherwise you’ll import the dump straight back into the production database. It’s the worst mistake you can make here. Second, wp search-replace handles serialized data (plugin settings, widgets) correctly, unlike a find-and-replace on the SQL file, which corrupts it. Third, the WP_ENVIRONMENT_TYPE constant tells WordPress and plugins they’re running on staging.
Then check the page source for leftover production URLs: anything hard-coded in the theme slips past the replacement.
Locking staging down and neutralising side effects
A staging site open to the world causes two problems. Google may index it, creating duplicate content alongside your real site, and anyone can get in, with customer data copied from production. The simplest, most reliable protection is HTTP authentication in front of the whole site:
# .htaccess for the staging site (Apache)
AuthType Basic
AuthName "Staging"
AuthUserFile /home/example/.htpasswd
Require valid-user
# Create the password file (once)
htpasswd -c /home/example/.htpasswd team
The “Discourage search engines from indexing this site” setting, which blog_public 0 switches on, is a complement, not protection. It only asks politely. A password actually blocks access.
The second risk is sneakier: a copy of your site keeps behaving like the real thing. It can email customers (abandoned cart reminders, order notifications, newsletters), take payments if the payment API keys are the live ones, send data to your analytics tools or sync contacts into your CRM. So we always add a small must-use plugin, loaded automatically and impossible to disable from the dashboard, which only kicks in outside production:
<?php
/**
* Plugin Name: Staging safeguards
* (wp-content/mu-plugins/staging-safeguards.php)
*/
if ( wp_get_environment_type() === 'production' ) {
return;
}
// 1. No email reaches real recipients
add_filter( 'wp_mail', function ( $args ) {
$recipients = implode( ', ', (array) $args['to'] );
$args['subject'] = '[STAGING for ' . $recipients . '] ' . $args['subject'];
$args['to'] = 'dev@example.com';
// Also strip copies (Cc / Bcc) added by plugins
$headers = is_array( $args['headers'] ) ? $args['headers'] : explode( "n", (string) $args['headers'] );
$args['headers'] = array_filter( $headers, fn( $h ) => ! preg_match( '/^s*b?ccs*:/i', $h ) );
return $args;
} );
// 2. Never indexed, even if the setting gets switched back on by mistake
add_filter( 'wp_robots', function ( $robots ) {
$robots['noindex'] = true;
$robots['nofollow'] = true;
return $robots;
} );
// 3. A visible marker in the admin bar
add_action( 'admin_bar_menu', function ( $bar ) {
$bar->add_node( [ 'id' => 'env-staging', 'title' => 'STAGING' ] );
}, 1 );
Then add whatever the site needs: switch the payment gateway to test mode with its test keys, use wp plugin deactivate on plugins that push data elsewhere (CRM, email marketing, product feeds), and remove or swap analytics IDs.
Working day to day without overwriting production
The rule that prevents almost every accident is simple: code goes up, data comes down. Code (theme, plugins, configuration) moves from staging to production. Data (posts, orders, customer accounts, comments) moves from production to staging when you refresh it, never the other way.
Why? Because production keeps living while you test. Pushing the staging database to production would wipe out every order, sign-up and message that arrived in the meantime. On a shop or a membership site, that’s plain data loss.
On our projects, that turns into the following cycle:
- refresh staging from production (same procedure as creating it, reusing the existing configuration);
- apply updates or deploy new code to staging, ideally from a Git repository;
- test the journeys that matter: contact form, checkout, customer login, search, the most visited pages;
- get the client’s sign-off if the change is visible;
- apply exactly the same changes to production, then run the same checks again.
Dashboard changes (menus, pages, plugin settings) live in the database, so redo them by hand in production after sign-off, or script them with WP-CLI. New content is best prepared directly in production as a draft.
FAQ
Isn’t a backup before each update enough?
A backup lets you roll back after something breaks; staging stops the breakage from reaching your visitors in the first place. They complement each other: keep regular backups, and test on staging.
How often should staging be refreshed?
Before any significant round of testing, and at the very least before every major update. A staging site that’s six months old no longer reflects the real one: plugins, content and settings have all moved on, and your tests lose their value.
Want to update your site without crossing your fingers? Our WordPress maintenance plans include a secure staging site and a tested update process.



