Zero-Downtime Host Migration: Step-by-Step Guide
In this article
Migrating a live website or application from one host to another without downtime is achievable with careful planning, a staged approach, and the right tools. This guide walks you through a proven method that keeps your service available throughout the process. You’ll need a basic understanding of DNS, SSH, and your hosting environment. The core idea is to set up the new host, sync data, test, then switch DNS while keeping both hosts running until the cutover is complete.
What You'll Need
- Access to both old and new hosting control panels (or command line via SSH).
- DNS management access (usually at your domain registrar or current host).
- A way to transfer files and databases (rsync, scp, mysqldump, or hosting backup tools).
- A staging URL or temporary subdomain pointing to the new host (e.g., staging.example.com).
- Ability to run a test of your application on the new host before cutover.
- A monitoring tool (like UptimeRobot or a simple cron job) to verify uptime.
Step-by-Step
- Inventory your current setup. Make a list of all files, databases, cron jobs, email accounts, SSL certificates, and any custom configurations (like .htaccess or nginx rules). Note the exact versions of your software (PHP, MySQL, etc.) to match on the new host.
- Provision the new host. Set up the new server with the same software versions and enable SSH access. Create the necessary databases and user accounts with the same credentials as the old host (or update your app config later).
- Copy your files. Use rsync over SSH to transfer your web files to the new host. For example:
rsync -avz /var/www/ user@newhost:/var/www/. If you have a large site, do an initial copy now; you'll sync again later. - Export and import your database. On the old host, dump the database:
mysqldump -u user -p dbname > db.sql. Then import it on the new host:mysql -u user -p dbname < db.sql. Ensure the database user has the correct privileges. - Configure the new environment. Update configuration files (like wp-config.php for WordPress or .env for Laravel) to point to the new database and paths. Also, set up any required cron jobs and email forwarding on the new host.
- Test on a staging URL. Create a subdomain (e.g., staging.yourdomain.com) that points to the new host's IP. Use your hosts file or a temporary redirect to test the site thoroughly: check pages, forms, database connections, and any APIs.
- Final sync. Just before cutover, put the old site into maintenance mode (if possible) to prevent changes. Then run rsync again to copy any changed files, and export/import the database one last time. This minimizes data loss.
- Switch DNS. Update your domain's A record (and www) to point to the new host's IP address. For email, update MX records if you're moving email servers. Set the TTL (time-to-live) to a low value (e.g., 300 seconds) a day before so changes propagate quickly.
- Monitor propagation. After DNS changes, watch the site from different locations. Use online DNS checkers to see when the new IP is live globally. Keep the old host running for at least 24-48 hours to catch any late requests.
- Verify and finalize. Once DNS has fully propagated (usually within 24-72 hours), confirm all functionality works. Then you can decommission the old host, but keep backups for a few weeks.
Common Mistakes
- Not matching software versions. If the new host runs PHP 8.0 and your app requires 7.4, you'll face errors. Always check compatibility.
- Forgetting cron jobs. Scheduled tasks like backups or email digests won't run on the new host unless you recreate them.
- Skipping the final sync. If you copy files and DB once and then switch DNS hours later, you'll lose any changes made in between. Always do a second sync right before cutover.
- Ignoring file permissions. Uploaded files and directories may have wrong ownership or permissions after transfer, causing 500 errors. Use the same user/group as the web server.
- Not testing email. If your site sends emails (e.g., contact forms), verify that the mail server on the new host is configured correctly, or you'll get silent failures.
Tips
- Use a load balancer or reverse proxy if you have complex traffic management; it can make cutover seamless.
- Keep the TTL of your DNS records low (e.g., 300 seconds) at least 24 hours before migration to speed up propagation.
- Take a full backup of the old host before starting, and store it off-site.
- If you're using CDN, purge the cache after DNS switch to avoid serving stale content.
- Schedule the migration during low-traffic hours to reduce the chance of user impact.
Troubleshooting
- Site shows old content after DNS switch. This is usually DNS caching. Wait 24-48 hours, and try clearing your local DNS cache or using a different network. If it persists, check that the A record actually points to the new IP.
- Database connection errors. Double-check your database hostname, username, and password in the config file. Ensure the database is imported and the user has privileges from the correct host (e.g., 'localhost' vs '%').
- Files missing or 404 errors. Verify the file paths are correct and that the document root on the new host matches your old setup. Use SSH to list files.
- SSL certificate not working. If you're using Let's Encrypt, you may need to re-issue the certificate on the new host. For custom certificates, ensure the private key and certificate files are uploaded correctly.
- Emails not sending. Check the mail server logs on the new host. You might need to configure SPF and DKIM records to avoid emails going to spam.
- Site is slow after migration. This could be due to caching not being enabled or missing PHP opcache. Also, check that the new host's hardware is comparable.
Frequently Asked Questions
How long does zero-downtime migration take?
It depends on the size of your site and DNS propagation. The actual file transfer and testing can take a few hours, but DNS propagation can take up to 72 hours. The site remains live throughout, so downtime is zero.
Can I migrate without changing DNS?
Yes, if you're moving within the same hosting provider or using a load balancer, you might be able to switch IPs internally. But for most cases, DNS change is required.
What if I don't have SSH access to the old host?
You can use your hosting control panel's backup and restore features, or use FTP to download files and phpMyAdmin to export the database. The process is slower but still works.
Will my SSL certificate work on the new host?
If you have a wildcard certificate or a dedicated IP, you can transfer the certificate files. For Let's Encrypt, you'll need to re-issue it on the new host, which is usually automated.
How do I handle a large database (e.g., >10GB)?
Use SSH to run mysqldump and pipe it directly to the new host via netcat or use a tool like 'mydumper' for faster parallel dumps. Avoid using phpMyAdmin for large databases as it may time out.
What if the new host has a different IP and I have third-party services pointing to the old IP?
Update those services with the new IP after DNS switch. For example, API integrations that use IP whitelisting will need the new IP added.