NewCode CLOUD — 20% off your first month on all cloud VPSClaim

How to Migrate a Website to a New Server with Minimal Downtime

Moving a website between servers does not have to mean hours of downtime. The method below copies everything while the old server keeps running, lets you test the new server privately, and then switches visitors over in minutes. It works for WordPress, Laravel, static sites and most PHP or Node.js applications.

Overview

  1. Lower the DNS TTL a day in advance.
  2. Prepare the new server.
  3. Copy files with rsync.
  4. Copy the database.
  5. Test the new server using your hosts file.
  6. Final sync, then switch DNS.
  7. Keep the old server for a few days.

1. Lower the DNS TTL (24 hours before)

At your DNS provider, change the TTL of your A records to 300 seconds (5 minutes). Resolvers will then pick up the new IP quickly on switch-over day. Wait at least as long as the old TTL (often 1–24 hours) before migrating.

2. Prepare the new server

Install the same stack as the old one — web server, PHP or Node.js version, database version and extensions:

# Example: Nginx, PHP 8.3 and MariaDB on Ubuntu 24.04
sudo apt update
sudo apt install -y nginx mariadb-server php8.3-fpm php8.3-mysql php8.3-curl php8.3-xml php8.3-mbstring php8.3-zip php8.3-gd

Follow the initial setup checklist first. Set up SSH key access from the new server to the old one so rsync can run without passwords.

3. Copy the files

Run this on the new server, pulling from the old one:

rsync -aHAX --info=progress2 --numeric-ids \
  root@OLD_SERVER_IP:/var/www/example.com/ /var/www/example.com/
  • -a keeps permissions, owners and timestamps; -H -A -X keep hard links, ACLs and extended attributes.
  • The trailing slashes matter: they copy the contents of the directory.
  • You can run the same command as many times as you like; later runs copy only what changed.

Also copy the web-server configuration (/etc/nginx/sites-available/ or /etc/apache2/sites-available/), cron jobs (crontab -l) and any SSL certificates you do not plan to re-issue.

4. Copy the database

On the old server, dump the database. --single-transaction takes a consistent snapshot of InnoDB tables without locking the site:

mysqldump --single-transaction --routines --triggers --default-character-set=utf8mb4 \
  -u root -p example_db | gzip > /root/example_db.sql.gz

Copy it to the new server and import:

# on the new server
rsync -a root@OLD_SERVER_IP:/root/example_db.sql.gz /root/
mysql -u root -p -e "CREATE DATABASE example_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD';
  GRANT ALL ON example_db.* TO 'example_user'@'localhost';"
gunzip < /root/example_db.sql.gz | mysql -u root -p example_db

Use the same database name, user and password as before, or update the application’s configuration file (wp-config.php, .env and so on).

5. Test privately with your hosts file

Before changing DNS, make only your computer resolve the domain to the new server. Add a line to your hosts file:

  • Windows: C:\Windows\System32\drivers\etc\hosts (edit as administrator)
  • macOS / Linux: /etc/hosts
NEW_SERVER_IP  example.com www.example.com

Open the site and check logins, forms, uploads, checkout and anything else that writes data. Look at the error logs on the new server (/var/log/nginx/error.log, PHP-FPM logs) while you click around.

If you use Let’s Encrypt, you cannot issue a new certificate until DNS points at the new server — copy the existing /etc/letsencrypt/ directory for testing, or test over HTTP first.

Remove the hosts entry when you are done.

6. Final sync and switch

Choose a quiet time. Then:

  1. Put the old site in maintenance mode, or stop writes (for WordPress, a maintenance plugin is enough).
  2. Run the rsync command from step 3 again — it only transfers changes, so it is fast.
  3. Dump and import the database again (step 4).
  4. Change the A records at your DNS provider to the new IP.
  5. On the new server, issue certificates: sudo certbot --nginx -d example.com -d www.example.com.

With a 300-second TTL, most visitors reach the new server within minutes.

7. Keep the old server for a few days

Some resolvers ignore TTLs, and mail or cron jobs may still point at the old IP. Keep the old server running, in maintenance mode, for a few days. Check its access log — when traffic stops, it is safe to cancel.

Checklist

  • TTL lowered 24 hours before
  • Same software versions on the new server
  • Files copied with rsync
  • Database exported and imported, application config updated
  • Cron jobs and web-server config copied
  • Site tested with a hosts-file override
  • Final sync done, DNS switched
  • SSL certificate issued on the new server
  • Old server kept until its traffic stops

Moving to Server.HK? Order a Hong Kong server or VPS and test the network first with the test IPs on each product page. If you would like advice on sizing, open a sales ticket.