Migrating a production WordPress site is a high-stakes operation. A poorly executed migration can mean hours of downtime, broken links, database corruption, or SEO penalties. After years of handling WordPress migrations—from small blogs to high-traffic e-commerce sites—I've developed a production-grade framework that prioritizes safety, verification, and reversibility at every step.
This guide covers the best practices that prevent outages and the anti-patterns that cause them, with rationale for each decision.
Pre-Migration Planning
Audit the Current Environment
Before touching production, document your existing setup completely. This creates your rollback reference and surfaces hidden dependencies.
Critical inventory checklist:
- PHP version, loaded extensions, and memory limits
- MySQL/MariaDB version and configured storage engine
- Active plugins and themes (including version numbers)
- Cron jobs, both WordPress and system-level
- Custom .htaccess rules or nginx configurations
- Third-party integrations (payment gateways, CDN, email services)
- SSL certificate type and renewal mechanism
- DNS records with current TTL values
Run this command on your source server to capture PHP configuration:
php -i > php-info-source.txt
mysql -V > mysql-version-source.txt
Export your DNS zone file before making any changes. Most hosting panels let you download a BIND-format zone file; keep it as your baseline.
Anti-pattern: Starting migration without documenting the source environment. When things break, you won't know what changed.
Choose Your DNS Strategy First
Your DNS approach dictates your migration timeline and rollback capability. Decide this before moving any files.
Low-TTL strategy (recommended for production):
Three days before migration, lower your domain's A record TTL to 300 seconds (5 minutes). This gives you fast switchover with quick rollback capability. Most production migrations should use this approach.
Hosts file testing:
For complex sites or first-time migrations, test the destination server using hosts file overrides before changing DNS. This lets you verify everything works without affecting users.
On Linux/Mac, edit /etc/hosts:
203.0.113.45 example.com www.example.com
On Windows, edit C:\Windows\System32\drivers\etc\hosts with the same format.
Anti-pattern: Changing DNS immediately after moving files, before verifying the new server works. This causes immediate user-facing outages with no quick recovery path.
Database Migration Best Practices
The database is your highest-risk component. Corruption here means data loss, not just downtime.
Export With Explicit Character Set
WordPress databases often mix UTF-8 collations. Explicit encoding prevents silent data corruption during import.
mysqldump -u username -p \
--default-character-set=utf8mb4 \
--single-transaction \
--routines \
--triggers \
--skip-lock-tables \
database_name > wordpress-backup.sql
Flag explanations:
--default-character-set=utf8mb4preserves emoji and special characters--single-transactioncreates consistent snapshot without locking tables (InnoDB only)--routines --triggerscaptures stored procedures if present--skip-lock-tablesprevents errors on limited-permission accounts
Anti-pattern: Using cPanel backup tools or plugins without verifying character set handling. This corrupts international characters and emoji silently.
Verify Export Integrity
Before importing anywhere, validate your SQL dump:
grep -i "Dump completed" wordpress-backup.sql
wc -l wordpress-backup.sql
The dump should end with a completion comment and have a reasonable line count based on your content volume. A truncated export is a common failure mode.
Search-Replace URLs Safely
WordPress serializes data in wp_options and wp_postmeta. Manual find-replace breaks serialized arrays by changing string length counts.
Use WP-CLI for safe search-replace:
wp search-replace 'https://oldsite.com' 'https://newsite.com' \
--all-tables \
--precise \
--dry-run
Review the dry-run output, then remove --dry-run to execute. This handles serialized data correctly and shows exactly what will change.
Anti-pattern: Using SQL UPDATE statements or generic search-replace tools. This corrupts serialized arrays and breaks widgets, options, and custom fields.
Import With Error Checking
Create the destination database with matching character set:
mysql -u username -p -e "CREATE DATABASE new_database \
CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
Import with verbose error reporting:
mysql -u username -p new_database < wordpress-backup.sql 2> import-errors.log
Check the error log. Any warnings about character sets, collations, or truncated data require investigation before proceeding.
File Transfer Best Practices
Use Rsync for Large Sites
For sites over 1GB or with thousands of files, rsync provides verification, resumability, and efficiency.
rsync -avz --progress \
/home/user/public_html/ \
[email protected]:/home/newuser/public_html/
Flags:
-apreserves permissions and timestamps-vshows file names as they transfer-zcompresses during transfer--progressdisplays transfer progress
For incremental sync after initial transfer:
rsync -avz --delete \
/home/user/public_html/ \
[email protected]:/home/newuser/public_html/
The --delete flag removes files on destination that don't exist on source, keeping environments identical.
Anti-pattern: Using FTP or cPanel file manager for large sites. These lack verification, corrupt files silently, and provide no resume capability.
Verify File Integrity Post-Transfer
Generate checksums on source:
cd /home/user/public_html
find . -type f -exec md5sum {} \; | sort -k 2 > ~/source-checksums.txt
Generate on destination and compare:
cd /home/newuser/public_html
find . -type f -exec md5sum {} \; | sort -k 2 > ~/dest-checksums.txt
diff ~/source-checksums.txt ~/dest-checksums.txt
Any differences indicate transfer corruption and must be resolved before going live.
Set Correct Ownership and Permissions
WordPress requires specific permission patterns for security and functionality:
chown -R username:username /home/newuser/public_html
find /home/newuser/public_html -type d -exec chmod 755 {} \;
find /home/newuser/public_html -type f -exec chmod 644 {} \;
Never use 777 permissions. If WordPress requests FTP credentials, fix ownership instead of opening permissions.
Configuration Update Checklist
Update wp-config.php
Minimum required changes:
define('DB_NAME', 'new_database_name');
define('DB_USER', 'new_database_user');
define('DB_PASSWORD', 'new_database_password');
define('DB_HOST', 'localhost'); // or new host if different
Production hardening additions:
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', false);
define('WP_DEBUG_DISPLAY', false);
define('DISALLOW_FILE_EDIT', true);
define('FORCE_SSL_ADMIN', true);
Regenerate security keys using the WordPress key generator and replace all eight salts. Reusing old keys from source reduces security.
Update Web Server Configuration
For Apache with mod_rewrite, verify .htaccess permalinks:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
For nginx, ensure your configuration includes:
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Anti-pattern: Copying web server configs without testing. Permalink rules and PHP handling differ between hosting environments.
SSL Certificate Management
SSL setup before DNS cutover prevents mixed-content errors and browser warnings.
Install Certificate Before Go-Live
Request and install your SSL certificate on the new server while still testing via hosts file. Most hosting providers offer free Let's Encrypt certificates through their control panel.
For manual Let's Encrypt with Certbot:
sudo certbot --nginx -d example.com -d www.example.com
Verify HTTPS works via hosts file testing before changing DNS.
Force HTTPS Site-Wide
Add to wp-config.php before the "stop editing" comment:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}
This handles proxy/load balancer SSL termination correctly.
Add to .htaccess after RewriteEngine On:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Anti-pattern: Forcing HTTPS in WordPress settings before SSL is installed. This creates a redirect loop that locks you out of wp-admin.
DNS Cutover Strategy
This is the moment of truth. A methodical approach prevents extended outages.
Perform Final Sync
Immediately before DNS change, run a final rsync to capture any content created during testing:
rsync -avz --delete /home/user/public_html/ [email protected]:/home/newuser/public_html/
Export and import database one final time if content was added during testing.
Update DNS Records
Change your A record to point to the new server IP. If using Cloudflare or another proxy, temporarily pause proxying to verify direct connectivity.
Update both root and www records:
A @ 203.0.113.45 300
A www 203.0.113.45 300
Keep the 300-second TTL for the first 24 hours to enable quick rollback.
Monitor Propagation
Use multiple DNS checkers from different global locations. Watch for:
- DNS propagation across regions
- SSL certificate validity on the new server
- Redirect chains (should be minimal)
- Core site functionality
Anti-pattern: Assuming DNS changes are instant. Propagation takes time, and cached records can persist beyond TTL values.
Post-Migration Verification
Systematic testing prevents discovering issues after users report them.
Functional Testing Checklist
- Homepage loads with all images and styles
- Login to wp-admin and verify dashboard loads
- Create test post and publish it
- Upload media to test file permissions
- Submit test form if using contact forms
- Complete test purchase if running e-commerce
- Check email delivery from contact forms and transactional emails
- Verify cron execution for scheduled posts and backups
- Test mobile rendering and responsive behavior
Performance Baseline
Capture performance metrics on the new server:
curl -o /dev/null -w "Connect: %{time_connect}s\nStart Transfer: %{time_starttransfer}s\nTotal: %{time_total}s\n" https://example.com
Compare to source server metrics. Significant degradation indicates resource constraints or misconfiguration.
Security Scan
Run a basic security check:
- Verify directory listing is disabled
- Test that wp-config.php is not web-accessible
- Confirm xmlrpc.php is blocked if not needed
- Check that readme.html and install.php are removed
- Verify database prefix is not the default
wp_
Anti-pattern: Considering migration complete when the homepage loads. Comprehensive testing catches issues before users do.
Common Anti-Patterns and Their Consequences
Migrating During Peak Traffic
Performing DNS cutover during high-traffic periods amplifies every issue. Cache misses, database connection limits, and resource exhaustion hit hardest when traffic is high. Schedule migrations during your documented low-traffic window.
Skipping Backup Verification
Taking a backup without verifying it restores successfully means discovering backup corruption during an emergency. Test your backup restoration process on a staging environment before relying on it.
Modifying Source and Destination Simultaneously
Changing content on the old server while setting up the new creates divergent states. Freeze content changes on source, complete migration, verify, then enable on destination. Document the freeze window in your runbook.
Using Different PHP/MySQL Versions Without Testing
Version jumps introduce deprecated functions, changed defaults, and incompatible extensions. Test your site on the destination's PHP/MySQL versions before migrating production. Use staging environments that match production exactly.
Ignoring Plugin Compatibility
Plugins that integrate external services, caching layers, or server-specific features often require reconfiguration post-migration. Document each plugin's settings before migration and verify functionality afterward.
Conclusion
Successful WordPress migration is about preparation, verification, and reversibility. Lower DNS TTLs early, document your source environment completely, use proper tools for database export and file transfer, verify every step before cutover, and maintain rollback capability throughout.
The anti-patterns—changing DNS before testing, skipping integrity verification, using improper tools—cause the outages and data corruption that give migrations their reputation for risk. Following production-grade practices transforms migration from a high-stress event into a methodical, low-risk operation.
Your first production migration should be your most conservative. Build runbooks, automate verification, and improve the process with each iteration. The goal is not just getting your site moved, but building a repeatable capability that lets you migrate confidently whenever needed.
