A WordPress staging site on VPS gives you a private copy of your live site where you can test updates, try new plugins, and break things without visitors ever noticing. The subdomain method is the most practical way to do it on a VPS: staging.yoursite.com behaves like a real site, runs on the same server stack, and stays separate from production. This guide builds one from scratch and shows how to use it safely.
Why a Staging Site Beats Testing on Live
Testing on a live site risks exactly the failures you want to catch: a plugin update that whitescreens the homepage, a theme change that breaks the checkout page, or a PHP upgrade that throws errors on one template. A staging copy catches those failures in private. It also gives you a place to measure: run a speed test before and after a change, and you know whether the change helped or hurt.
Local test environments have their place, but they rarely match the server. Different PHP versions, missing extensions, and different caching layers mean a change can pass locally and fail on the server. A staging site on the same VPS removes that gap because the stack is identical.
Staging Subdomain Setup: DNS and Server Block
Start with DNS. Add an A record for staging.yoursite.com pointing at your VPS IP address, or a wildcard record if you plan several staging copies. DNS changes can take minutes or hours to spread, so create the record before you need the site.
Next, create the server block. If you built the stack yourself, follow the same pattern as your live site: a new Nginx server block for staging.yoursite.com, a document root such as /var/www/staging.yoursite.com, and a PHP-FPM pool or shared pool depending on your setup. The steps mirror a fresh install, and installing WordPress on a VPS LEMP stack with Nginx, PHP, and MariaDB covers the server block pattern in detail. Issue a free SSL certificate for the subdomain too, so staging matches production including HTTPS behavior.
Copy the Files to Staging
Copy the live document root to the staging root, excluding cache folders and large backup archives you do not need:
rsync -av --exclude='wp-content/cache/' /var/www/yoursite.com/ /var/www/staging.yoursite.com/
Set ownership to your web user after copying. Files copied as root with wrong ownership cause upload and update failures that look like plugin bugs but are really permission problems.
Copy the Database and Rewrite the URLs
Export the live database and import it into a new, separate database for staging. Never point staging at the live database: a test order, a test post, or a settings change would then hit production data.
mysqldump -u USER -p live_db > live_db.sql mysql -u USER -p staging_db < live_db.sql
Then replace the live domain with the staging domain inside the new database. The wp-cli search-replace command handles serialized data correctly, which a plain text find-and-replace does not:
wp search-replace 'yoursite.com' 'staging.yoursite.com' --all-tables --path=/var/www/staging.yoursite.com
Update wp-config.php in the staging root to use the staging database name, user, and password. Open staging.yoursite.com and confirm the homepage, admin area, and a few inner pages all load.
Block Search Engines and Lock the Door
A staging site must never appear in search results or get indexed as duplicate content. Add a robots rule, enable the built-in search engine visibility setting in WordPress admin under Settings, Reading, and then go further: password-protect the whole subdomain with HTTP basic auth in Nginx. Basic auth stops search engines, scrapers, and curious visitors in one move, and it costs nothing to set up. Only people with the password can even load the staging homepage.
Test WordPress Changes Safely: A Working Routine
A staging site only helps if you use it the same way every time. A reliable routine looks like this:
- Sync staging from live so the test starts from current data.
- Make one change at a time: one plugin update, one theme edit, one settings change.
- Check the homepage, a post, a page with a form, and the checkout or contact flow if the site has one.
- Check the PHP error log after each change, not just the visible pages.
- Write down what passed before moving to the next change.
This discipline matters because a VPS staging environment can hide problems when several changes land at once. When a test fails, you want to know which single change caused it.
Pushing Changes From a WordPress Staging Site on VPS to Live
Moving file changes back is straightforward: copy the changed theme or plugin files to live, or re-apply the same edits there. Database changes are harder. If staging and live both took new orders, comments, or form entries since the sync, merging databases by hand is risky. The safer pattern is to treat staging as a test ground, not an editing ground: test on staging, then apply the winning change to live by repeating the same steps there. Content edits belong on live directly, or on staging only when the site is quiet enough that nothing changes on live meanwhile.
For sites with caching, remember that staging and live caches are separate. Configuring Nginx FastCGI cache for WordPress without a plugin explains the cache layer, and the same rules apply on staging: purge the staging cache after each change or you will test a stale page and wonder why nothing changed.
Subdomain Versus Other Staging Options
| Method | Matches server | Risk of confusion |
|---|---|---|
| Subdomain on same VPS | Yes, identical stack | Low with basic auth |
| Subfolder on live domain | Yes | Higher, URLs can leak |
| Local machine | Rarely | Low, but results differ |
| Separate staging server | Only if stacks match | Low, costs more |
The subdomain method wins on most VPS setups because it is cheap, matches production, and stays clearly separate. If you run several sites on one server, the same pattern scales: one staging subdomain per site. Running multiple WordPress sites on one VPS with Docker shows how site separation works when the server hosts more than one project.
Common Staging Mistakes
- Pointing staging at the live database, which turns every test into a live change.
- Forgetting basic auth, which lets search engines index the staging copy.
- Testing with stale data, so the test passes on old content and fails on current content.
- Leaving staging un-updated for months, until it no longer resembles live at all.
Re-sync staging from live on a schedule, or at least before every important test. A staging copy that drifted far from production gives false confidence, which is worse than no test at all.
Set the subdomain up once, protect it, and make it part of every update. The hour spent building a WordPress staging site on VPS pays for itself the first time a plugin update fails in private instead of in front of your visitors.