//Servers

Seamless Site Migration: Zero‑Downtime Hosting Guide

Learn how to migrate a website to a new host with zero downtime—step‑by‑step prep, sync, DNS switch, and post‑migration checks for a smooth transition.

5 min read
Seamless Site Migration: Zero‑Downtime Hosting Guide

Moving a website to a new hosting provider can feel risky, especially when any interruption would affect visitors or customers. With careful planning and the right tools, you can migrate your site with zero downtime. This guide walks you through each phase—pre‑migration checks, data transfer, DNS switchover, and post‑migration validation—so the transition is smooth and transparent.

1. Prepare the New Server

Set up the target environment so it matches your current production stack. Replicate the operating system, web server, database engine, runtime (PHP, etc.), and any required extensions.

  • Match the OS version (e.g., Ubuntu 22.04 LTS, Debian 12, AlmaLinux 9) to avoid compatibility surprises.
  • Install the same web server—Apache, Nginx, or another—using the appropriate package manager.
  • Set up the database (MySQL/MariaDB, PostgreSQL, etc.) and create a user with identical privileges.
  • Configure the runtime (PHP, Python, Node.js, …) to the same version and enable required extensions.

Below are the basic commands for the two most common Linux families. Adjust package names if you use a different stack.

Debian / Ubuntu (apt)

# Update the package index
sudo apt update

# Install Nginx, PHP 8.2 (with FPM) and the MySQL client
sudo apt install -y nginx php8.2 php8.2-fpm php8.2-mysql mysql-client

# Verify that the services are running
systemctl status nginx
systemctl status php8.2-fpm

AlmaLinux / Rocky / RHEL (dnf)

# Refresh repository metadata
sudo dnf makecache

# Install Nginx, PHP (with FPM) and the MariaDB client
sudo dnf install -y nginx php php-fpm php-mysqlnd mariadb

# Enable and start the services immediately
sudo systemctl enable --now nginx
sudo systemctl enable --now php-fpm

On Windows Server you would use the Web Platform Installer or manually download the required binaries. The principle is the same: replicate the software stack before moving any data.

2. Sync Files and Databases While Keeping the Source Live

Copy the website files and database to the new server while the old site continues to serve traffic. Use rsync for files and mysqldump (or pg_dump) for databases.

Copy Files with rsync

Run the command from the new server, pulling data from the old host. Replace old_user, old_host, and /var/www/html with your actual usernames and paths.

# Pull website files, preserving permissions and timestamps
rsync -avz --delete old_user@old_host:/var/www/html/ /var/www/html/

The -a flag preserves attributes, -v shows progress, -z compresses data during transfer, and --delete removes files on the destination that no longer exist on the source.

Export and Import the Database

# Export the database from the old host (run on the old host or via SSH)
mysqldump -u db_user -p'password' --single-transaction --quick db_name > /tmp/db_name.sql

# Transfer the dump file to the new server
scp /tmp/db_name.sql new_user@new_host:/tmp/

# Import the dump into the new MySQL/MariaDB instance
mysql -u db_user -p'password' db_name < /tmp/db_name.sql

The --single-transaction option creates a consistent snapshot without locking InnoDB tables.

3. Test the New Environment Thoroughly

Before pointing real users to the new server, verify that everything works exactly as it did on the old host.

  • File permissions—ensure the web‑server user (e.g., www-data or nginx) can read the site files.
  • Database connectivity—run a simple query from the application.
  • SSL certificates—use a self‑signed certificate or a temporary Let’s Encrypt certificate for testing.
  • Hosts‑file override—map the domain to the new IP on your workstation without affecting public DNS.

Example hosts‑file entry (Linux/macOS):

# /etc/hosts
203.0.113.45   www.example.com

After editing, clear your browser cache and browse the site. Look for missing assets, 500 errors, or broken forms. Run any automated test suites you have, and check server logs (/var/log/nginx/error.log, /var/log/php-fpm.log, etc.) for warnings.

4. Perform a Final Sync and Switch DNS

Even after a successful test, the live site may have received new content or database updates since the initial sync. Perform a short “final sync” window (usually a few minutes) to capture any changes.

Final File Sync

# Pull any new or changed files
rsync -avz --delete old_user@old_host:/var/www/html/ /var/www/html/

Final Database Dump

# Optionally put the old database in read‑only mode
mysql -u root -p -e "FLUSH TABLES WITH READ LOCK;"

# Export the latest data
mysqldump -u db_user -p'password' --single-transaction db_name > /tmp/db_name_final.sql

# Unlock the tables
mysql -u root -p -e "UNLOCK TABLES;"

# Transfer and import as before
scp /tmp/db_name_final.sql new_user@new_host:/tmp/
mysql -u db_user -p'password' db_name < /tmp/db_name_final.sql

Now update the DNS records to point to the new IP address. Reduce the TTL a day before migration (e.g., from 86400 seconds to 300 seconds) so the change propagates quickly. After the switch, monitor traffic and error logs for at least an hour.

5. Keep the Old Host Running for a Grace Period

Some visitors may still be cached to the old IP. Keep the previous server active for 24–48 hours, but configure it to serve a simple “maintenance” page or redirect all requests to the new host.

# Example Nginx config on the old server
server {
    listen 80;
    server_name www.example.com;

    return 301 https://www.example.com$request_uri;
}

After confirming that traffic has fully migrated (use analytics or server access logs), you can safely decommission the old instance.

Conclusion

Migrating a website without downtime is a matter of preparation, precise data syncing, and controlled DNS changes. By replicating the production environment, using rsync and database dumps for incremental transfers, testing with a hosts‑file override, and keeping the original server live for a short grace period, you ensure a seamless experience for users. Follow the steps above, adapt them to your specific stack, and your next host migration will be a routine operation rather than a stressful event.

website migrationzero downtimersyncmysqldumpdns switchoverserver provisioninglinux hostingssl testing

Try it on your own server

Follow along on a Cloud VPS with full root access, or read the step-by-step knowledge base guides.