Logo
Bearhost Logo

How to Set Up a Staging Website

By Elliot, BearHost·

A staging website is a private clone of your live site where you can test changes without affecting your visitors. This is essential for testing WordPress updates, plugin changes, and design modifications.

Why Use a Staging Site?

  • Test updates safely — plugin and theme updates can break your site
  • Develop new features — build and refine before going live
  • Debug issues — reproduce and fix problems without downtime
  • Client approval — show changes to clients before publishing

Method 1: Manual cPanel Setup

Step 1: Create a Subdomain

  1. Go to cPanel > Domains > Subdomains (or Domains on newer cPanel)
  2. Create staging.yourdomain.com
  3. Set the document root to /home/username/staging.yourdomain.com

Step 2: Copy Website Files

In cPanel > Terminal or via SSH:

cp -R /home/username/public_html/* /home/username/staging.yourdomain.com/

Or use File Manager to copy the contents of public_html to the staging directory.

Step 3: Clone the Database

  1. Go to cPanel > phpMyAdmin
  2. Select your live database
  3. Click Export > Quick > Go to download a SQL file
  4. Create a new database in cPanel > MySQL Databases:
    • Create database: username_staging
    • Create user: username_staginguser
    • Add user to database with All Privileges
  5. In phpMyAdmin, select the new database
  6. Click Import > select the SQL file > Go

Step 4: Update wp-config.php

Edit wp-config.php in the staging directory:

define( 'DB_NAME', 'username_staging' );
define( 'DB_USER', 'username_staginguser' );
define( 'DB_PASSWORD', 'your_staging_db_password' );

Step 5: Search and Replace URLs

The database contains your live domain in hundreds of places. Use a search-replace tool.

In phpMyAdmin, for the staging database, go to the SQL tab:

UPDATE wp_options SET option_value = REPLACE(option_value, 'https://yourdomain.com', 'https://staging.yourdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

For a thorough replacement, use the Better Search Replace plugin or the WP-CLI command:

wp search-replace 'https://yourdomain.com' 'https://staging.yourdomain.com' --path=/home/username/staging.yourdomain.com

Step 6: Password-Protect the Staging Site

In cPanel > Directory Privacy, select the staging directory and enable password protection. This prevents public access.

Step 7: Block Search Engines

Add to the staging site's wp-config.php:

define( 'WP_ENVIRONMENT_TYPE', 'staging' );

In WordPress, go to Settings > Reading and check Discourage search engines from indexing this site.

Also add to the staging .htaccess:

Header set X-Robots-Tag "noindex, nofollow"

Method 2: WP Staging Plugin (Easier)

The WP Staging plugin automates the entire process.

Setup

  1. Install WP Staging from Plugins > Add New
  2. Activate the plugin
  3. Go to WP Staging > Staging Sites
  4. Click Create New Staging Site
  5. Optionally exclude large directories (uploads) or database tables to speed up cloning
  6. Click Start Cloning

The plugin creates the staging site at yourdomain.com/staging (or your chosen name).

Using the Staging Site

  1. Access your staging site at the URL provided
  2. Log in with the same WordPress credentials
  3. The admin bar shows an orange "STAGING" label so you always know which site you are on
  4. Make your changes, test thoroughly

Push Staging to Production (Pro Feature)

WP Staging Pro allows pushing changes from staging back to production:

  1. On the staging site, go to WP Staging > Push Changes
  2. Select what to push (files, database, or both)
  3. Exclude sensitive files (wp-config.php)
  4. Click Push

Pushing Manual Staging to Production

If you used the manual method:

  1. Back up your live site first
  2. Copy modified files from staging to production
  3. Export the staging database and import into the live database
  4. Run search-replace to change staging URLs back to live URLs
  5. Clear all caches

Best Practices

  • Always back up before pushing staging to production
  • Keep staging in sync — re-clone periodically to avoid drift
  • Never index staging sites — always block search engines
  • Use the same PHP version on staging as production
  • Test on staging first — every time, without exception
  • Delete old staging sites when no longer needed to save disk space
Tags:#staging#wordpress#cpanel#development#subdomain#wp-staging#testing