A staging environment lets you test changes before applying them to production. This guide creates a full staging copy using a subdomain.
Step 1 — Create Staging Subdomain and Copy Files
sudo rsync -avz /var/www/production/ /var/www/staging/
sudo chown -R www-data:www-data /var/www/staging
Step 2 — Clone Database
wp --path=/var/www/production db export /tmp/production.sql
mysql -u root -p -e "CREATE DATABASE staging_db;"
mysql -u root -p staging_db < /tmp/production.sql
wp --path=/var/www/staging search-replace 'yourdomain.com' 'staging.yourdomain.com' --all-tables
Step 3 — Update wp-config.php for Staging
define('DB_NAME', 'staging_db');
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Step 4 — Protect from Search Engines
WordPress Admin → Settings → Reading → Discourage search engines from indexing this site
Conclusion
A staging environment prevents costly production mistakes. Our team sets up staging environments for WordPress clients.
Comments