How to Set Up a Staging Site on Your VPS Before Going Live

Every WordPress owner has done it at least once: clicked update on a plugin, refreshed the live site, and watched the layout fall apart in front of real visitors. A staging site on your VPS gives you a private copy where that kind of accident costs nothing: test the update there, fix what breaks, and only then move the change to production.

A staging site is a separate copy of your live site that runs on the same server or a second one. Visitors never see it, search engines should never index it, and mistakes inside it stay inside it.

What a Staging Site Is and Why Your VPS Needs One

On shared hosting, staging often comes as a button in the control panel. On a VPS, you build it yourself, which is both the drawback and the advantage: you control exactly what gets copied, where it lives, and how closely it mirrors production.

That control matters because a useful staging copy has to behave like the real site: same PHP version, same web server settings, same plugins and theme. A plugin that works in staging on a different PHP version can still crash live, so keep the two environments as close as you can.

Staging earns its keep in a few specific moments: before a WordPress core update, before installing a new plugin or theme, before editing theme files, and before any change to the database.

Pick Your Setup: Subdomain, Subdirectory, or a Second VPS

Most VPS owners choose one of three layouts, and the right one depends on how much isolation you need and how much disk you can spare.

A subdomain is the most common choice, something like staging.yoursite.com. It gets its own nginx server block, document root, and database, so it behaves like a separate site, which makes it the easiest layout to reason about and lock down. A staging subdomain setup also keeps URLs clean, since WordPress stores the site address in the database and a subdomain maps to it directly.

A subdirectory, like yoursite.com/staging, costs nothing extra in DNS and needs no new server block. The trade-off is that it shares the live site’s domain and nginx rules, so a misconfigured redirect or a plugin that writes absolute URLs can leak staging content into production, or the other way round.

A second VPS gives full isolation: its own PHP version, cache settings, and database server. That is the safest option for high-traffic sites, but it doubles your server bill and your maintenance. For a small or medium site, a subdomain on the same VPS is the sweet spot.

Prepare the Staging Copy: Files, Database, and Config

Start by copying the live site’s files with rsync, so later refreshes skip unchanged files:

rsync -av --exclude='wp-content/cache/' /var/www/yoursite.com/ /var/www/staging.yoursite.com/

Next, copy the database: export it with mysqldump, create a new empty database, and import the dump:

mysqldump -u live_user -p live_db > /tmp/live-db.sql
mysql -u staging_user -p -e "CREATE DATABASE staging_db;"
mysql -u staging_user -p staging_db < /tmp/live-db.sql

Then point staging at its new database and domain: edit wp-config.php in the staging folder with the new database name, user, and password, then replace the live domain with the staging domain inside the database. WP-CLI handles this safely because it updates serialized data correctly, where a plain text find-and-replace would corrupt it:

wp search-replace 'https://yoursite.com' 'https://staging.yoursite.com' --all-tables --path=/var/www/staging.yoursite.com

If you skip the search-replace step, staging will keep redirecting to the live domain, which is the single most common staging mistake. If your site is a WordPress staging site VPS copy built with a plugin instead, the same rule applies: the domain inside the database must match the domain the server block answers on. For a general cloning walkthrough, the guide to cloning a WordPress site for testing covers the same copy in more detail.

Set Up a Staging Site on Your VPS: Step by Step

1. Create the DNS record

Add an A record for staging.yoursite.com pointing at your VPS IP. If your live site uses Cloudflare, add the record there too.

2. Add the nginx server block

Create a server block for the staging domain that mirrors the live one, with the document root pointed at the staging folder. Copy the live vhost file, change the server name and root paths, then test the config:

sudo nginx -t && sudo systemctl reload nginx

3. Get an SSL certificate

Issue a certificate for the staging subdomain with Certbot; a wildcard certificate covers it automatically. The guide to pointing a new domain to your VPS with free HTTPS walks through the Certbot steps.

4. Fix file ownership and permissions

Make sure the staging files belong to the same user and group as the live site, usually www-data. Wrong ownership is the usual cause of the white screen or the “unable to write” errors right after copying a site.

5. Check the site loads

Open the staging URL, log in to /wp-admin, and open a few pages. If anything redirects to the live domain, the search-replace step missed a table, so run it again with --all-tables and check the wp_options values for siteurl and home directly.

Lock It Down So Search Engines and Visitors Stay Out

An open staging site is a duplicate of your live site, and Google will index it if it can reach it, splitting your search traffic and exposing unfinished pages. Lock it down the day you create it, not later.

Basic authentication in nginx is the simplest lock. Add auth_basic to the staging server block and generate a password file with htpasswd. Anyone who opens the staging URL then needs a username and password before WordPress even loads, which also blocks crawlers.

As a second layer, check “Discourage search engines from indexing this site” under Settings, then Reading in the staging dashboard. It adds a noindex tag and blocks crawlers through robots.txt, but it is a backup, not a replacement for basic auth, since a crawler can ignore robots.txt.

Also turn off outgoing email from staging. A staging copy with working mail can send password resets and order confirmations to real customers, so route mail to a test address or block outbound SMTP from the staging site in your firewall.

Test Your Changes Properly Before Going Live

A vps staging environment only helps if you use it the way production gets used. Clicking through the homepage is not a test. Run the flows your visitors depend on: log in, submit the contact form, add a product to the cart, complete a checkout with a test payment, and open the site on a phone.

Check the error logs after each change. WordPress hides many problems behind a page that looks fine while PHP warnings pile up in the log, so tail it while you test:

sudo tail -f /var/log/nginx/staging.yoursite.com-error.log

Watch disk space too. Staging doubles the files and the database, and a site with large uploads can eat a small VPS disk fast, so set up disk space alerts on your VPS to catch a full disk before it surprises you mid-test. Logs grow as well, so keep log rotation configured on both the live and staging sites.

Keep staging in sync with production. A copy from three months ago tests against old content and old plugin versions, which tells you little about what will happen today. Refresh it before any major change: re-copy the files, re-import a fresh database dump, and run the search-replace again.

Push Staging to Production Without Breaking the Live Site

Moving changes back to production is where most staging setups fail, because copying everything at once is tempting. Do not copy the staging database over the live one: it holds new orders, comments, and user registrations that staging does not, and overwriting it deletes real data.

Move code, not content. Copy changed theme files, the new plugin, or the edited template from staging to live with rsync, then activate it on the live site. If you edited content in staging, recreate those edits on live, or use a migration plugin that moves only the specific posts and settings you changed.

Before you push, back up the live site: a full file and database backup takes a few minutes and turns a bad deploy into a ten-minute restore instead of a lost evening. After pushing, test the live site the same way you tested staging: the same pages, forms, and checkout flow.

Once the change is live and confirmed working, refresh the staging copy from production so the two match again. A staging site that drifts from production stops being a reliable test, and the next update gets tested against a site that no longer exists.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.