W
WordPress SOPKnowledge Base
Search
← All topics

WordPress Staging Environments

runnable

WordPress staging setup options (Local by Flywheel, MainWP Staging, manual VPS clone), WP-CLI staging commands, staging wp-config settings to block indexing and trap emails.

stagingdevelopmentlocalwp-clideployment
Agent trigger phrases: wordpress staging · staging environment wordpress · local by flywheel · wordpress test site · clone wordpress to staging · staging wp-config · prevent staging indexing

Always test on staging before pushing to production. Never develop on a live site.

Staging Options

| Method | Best For | Cost | |--------|----------|------| | Local by Flywheel | Local dev, no server needed | Free | | WP Engine staging | Managed hosting clients | Included | | MainWP Staging extension | Fleet management via MainWP | MainWP plan | | WPvivid staging | Any shared/VPS hosting | Free/paid | | Manual clone (WP-CLI + rsync) | VPS clients, full control | $0 | | Hostinger staging | hPanel one-click | Included | | WPX staging | WPX control panel one-click | Included |

Manual Staging Setup (VPS)

# 1. Create staging database
mysql -u root -p -e "CREATE DATABASE staging_mysite CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -u root -p -e "CREATE USER 'staging_user'@'localhost' IDENTIFIED BY 'password';"
mysql -u root -p -e "GRANT ALL PRIVILEGES ON staging_mysite.* TO 'staging_user'@'localhost';"

# 2. Copy files (excluding wp-config.php)
rsync -av /var/www/production/ /var/www/staging/ --exclude=wp-config.php

# 3. Export production DB and import to staging
wp db export /tmp/prod-db.sql --path=/var/www/production
wp db import /tmp/prod-db.sql --path=/var/www/staging

# 4. Update staging wp-config.php with staging DB credentials
# 5. Search-replace URLs
wp search-replace 'https://production.com' 'https://staging.production.com' \
  --all-tables --path=/var/www/staging

Staging wp-config.php Settings

// Identify environment
define('WP_ENVIRONMENT_TYPE', 'staging');

// Prevent search engine indexing
define('DISALLOW_INDEXING', true);

// Block outgoing emails (trap locally)
add_filter('wp_mail', function($args) {
    $args['to'] = 'dev@agency.com'; // redirect all email to dev
    return $args;
});

Block Indexing Programmatically

// In staging wp-config.php or functions.php
if (strpos($_SERVER['HTTP_HOST'] ?? '', 'staging') !== false) {
    add_action('pre_option_blog_public', '__return_zero');
}

Push Staging to Production

  1. Run full test on staging — forms, checkout, layout, performance
  2. Export staging DB changes
  3. Import to production (or use WPvivid push feature)
  4. Sync uploads/ if new media was added: rsync -av staging/wp-content/uploads/ production/wp-content/uploads/
  5. Never push staging wp-config.php to production