Family Encyclopedia >> Electronics

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

As WordPress users advance from beginners to professionals, their sites evolve into critical business assets. Editing live sites directly risks downtime, errors, and lost revenue. Many of our clients have requested a reliable tutorial on creating a staging environment. In this guide, drawn from years of managing production WordPress sites, we'll walk you through setting up a test environment to safely develop and test changes.

Note: Ideal for developers transitioning from basic to advanced workflows, this tutorial curbs 'cowboy coding' and instills best practices. By the end, you'll master:

  • Creating a staging site
  • Integrating Git and Bitbucket
  • Pushing local changes to Bitbucket
  • Deploying from Bitbucket to staging

What is a Staging Environment?

For local development, we always recommend installing WordPress on your Windows or Mac machine. Once perfected locally, migrate to production. But what if local tweaks break on the live server? Issues like plugin conflicts or theme glitches can tank SEO, sales, and user trust.

The solution: A staging site—a cloned, restricted version (often a subdomain) on your production server. Test thoroughly here before promoting to live. For beginners avoiding complexity, opt for managed hosts like WP Engine (built-in staging) or SiteGround's affordable GrowBig plan.

Setting Up Staging with cPanel

Start by creating a subdomain for isolation—it runs independently without touching your main database, files, or uploads.

Log into cPanel (similar in other panels; search Domains or Subdomains). Under Domains, click Subdomains.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Enter a name like staging or dev, select your domain, and let cPanel auto-fill the Document Root (e.g., public_html/staging). Click Create.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step GuideHow to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step GuideHow to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Verify by visiting the subdomain—it should display a default page.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Create a dedicated FTP account for staging security.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

In FTP Accounts, fill details matching your subdomain's directory. Click Create FTP Account.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Copying Data from Live to Staging

Clone your live database and files for realistic testing.

Via cPanel's phpMyAdmin, select your live database, go to Operations.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Under Copy database to, name your staging DB (create first if needed, e.g., example_staging). Copy structure and data, then Go.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Select the new DB, click SQL, and run these queries to update URLs:

UPDATE wp_options SET option_value = REPLACE(option_value, 'ORIGINAL_URL', 'NEW_URL');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'ORIGINAL_URL', 'NEW_URL');
UPDATE wp_posts SET guid = REPLACE(guid, 'ORIGINAL_URL', 'NEW_URL');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'ORIGINAL_URL', 'NEW_URL');

Replace ORIGINAL_URL (e.g., https://example.com from Settings > General) and NEW_URL (e.g., https://staging.example.com). Adjust wp_ prefix if custom.

  • ORIGINAL_URL: Live site URL
  • NEW_URL: Staging subdomain (include https://)
  • wp_: Use your table prefix

Download fresh WordPress from WordPress.org, upload to staging (don't install yet). Copy /wp-content/uploads, /themes, /plugins:

  • Use FTP for small sites
  • For large: cPanel File Manager

Open File Manager, navigate to public_html/wp-content.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step GuideHow to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Right-click each folder > Copy to /public_html/staging/wp-content/.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step GuideHow to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Note: If File Manager unavailable, FTP or SSH.

Visit staging; update wp-config.php with staging DB details. Log in with live credentials—changes are now isolated.

Configuring and Troubleshooting Staging

Post-login essentials:

Verify Domain: Check admin URL matches subdomain. Fix wp_options table if needed (siteurl/home).

Check Media: Media library should show uploads.

Disable XML Sitemaps: In Yoast SEO, turn off to avoid indexing.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Restrict Access: Install 'Restrict Site Access' plugin; configure under Settings > Reading. Also, uncheck search engine visibility. Add .htaccess password protection for /wp-admin/ or root.

Flush Permalinks: Settings > Permalinks > Save to fix 404s.

Using Git and Bitbucket for Version Control

Pros use Git (via GitHub/Bitbucket) for history, rollbacks, and collaboration.

GitHub vs. Bitbucket

GitHub suits open-source (free public repos; paid private). Bitbucket offers free private repos—perfect for client/personal sites.

Getting Started with Bitbucket

1. Install Git: Download for Windows/Mac.

2. Create Repo: Sign up at Bitbucket, Create repository (private, Git).

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step GuideHow to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Choose 'I have an existing project'.

3. Init Local Repo: Git Bash: cd to project (e.g., /C/xampp/htdocs/wordpress/wp-content/themes/myawesometheme)

git init
git add .
git commit -m "Initial project commit"

4. Link & Push:

git remote add origin https://admin@989214.com/bitbucketusername/repositoryname.git
git push -u origin --all

For changes:

git add .
git commit -m "Added new features"
git push -u origin --all

Deploying Bitbucket Changes to Staging

Use Ftploy (free tier): Sign up, add server with staging FTP details.

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step GuideHow to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Test connection, save. New Project > Bitbucket > Select server/path (e.g., /wp-content/themes/your-theme).

How to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step GuideHow to Set Up a Staging Environment for Your WordPress Site: Expert Step-by-Step Guide

Pushes auto-deploy.

Deploying to Live

Ftploy shines for staging; for live, manual copy after staging tests to avoid errors. See our WordPress errors guide for troubleshooting.

We hope this empowers safer WordPress development. Questions? Comment below.