How to Migrate WordPress to a New Host with Zero Downtime
Achieving zero downtime during a WordPress migration requires keeping your old host active while configuring the new host, testing the setup locally, and then seamlessly routing traffic via DNS. This technical guide covers the manual migration process using the command line.
Step 1: Export Files and Database from the Old Host
Compress your WordPress files and export the MySQL database. Using SSH is faster and less error-prone than FTP.
Compress the public_html directory:
tar -czf wordpress_files.tar.gz /path/to/wordpress/public_html
Export the database using mysqldump:
mysqldump -u db_user -p db_name > wordpress_db.sql
Step 2: Import Files and Database to the New Host
Transfer the archive and SQL file to your new server using SCP or SFTP, then extract them.
Extract the files in your new document root:
tar -xzf wordpress_files.tar.gz -C /path/to/new/public_html
Create a new database on the destination server, then import the SQL file:
mysql -u new_db_user -p new_db_name < wordpress_db.sql
Open wp-config.php on the new server and update the database credentials:
define('DB_NAME', 'new_db_name');
define('DB_USER', 'new_db_user');
define('DB_PASSWORD', 'new_db_password');
define('DB_HOST', 'localhost');
Step 3: Test the New Server Locally
To ensure the site works on the new host before changing public DNS, map your domain to the new server's IP address on your local computer using the hosts file.
On macOS or Linux, edit /etc/hosts. On Windows, edit C:\Windows\System32\drivers\etc\hosts. Add the following line (replace with your new server IP and domain):
203.0.113.50 example.com www.example.com
Save the file and clear your browser cache. Visit your domain. You are now viewing the site hosted on the new server. Verify page loads, media files, and admin login functionality.
Step 4: Lower DNS TTL and Update Records
DNS propagation can take up to 48 hours. To minimize this window, adjust your Time to Live (TTL) settings.
- 24 Hours Before Migration: Log into your DNS provider (e.g., Cloudflare, Route 53) and lower the TTL of your A records to 300 seconds (5 minutes).
- During Migration: Once the local test in Step 3 succeeds, update your DNS A records to point to the new server's IP address.
Step 5: Keep Both Servers Active During Propagation
Because some DNS resolvers cache old records despite low TTLs, some visitors will hit the old server while others hit the new one.
- Keep the old hosting account active for at least 48 hours after updating DNS.
- If your site handles dynamic data (like WooCommerce orders or active comments), temporarily disable comments and place the old site in read-only mode, or use a database replication tool during the transition to prevent data split.
Need this done? We handle this hands-on at GuardLabs (https://guardlabs.online/) — get in touch for a quote.
Top comments (0)