Skip to main content

Business tech · Intermediate · 25 min

How to Move a Website to a New Host Without Downtime

By Padding · Updated 16 Nov 2026
Any host

You will move a website to a new server with no visible outage by lowering the DNS TTL first, copying files and the database, testing the new server before anyone is sent to it, cutting over with a DNS change, checking the result, and only then raising the TTL and retiring the old host.

On this page

Moving a website to a new server fails in two ways. The first is a visible outage: you switch the address, the new server is not ready, and visitors see errors. The second is quieter: for hours, some visitors reach the old server and some the new one, so orders, comments or sign-ups land in two databases, and one set is lost when you switch the old server off. Both are avoidable. The method is the same for a static site, a WordPress blog or an application: prepare the new host completely, test it while nobody else uses it, then change DNS and let the old host keep answering until the change has spread.

The tool that makes this safe is the DNS TTL, the number of seconds that other computers may remember your records. If your A record has a TTL of one day, then after you change the address, some visitors keep going to the old server for up to a day. Lower the TTL days before you move, and the same spread takes minutes.

Read the whole tutorial before you start. The steps that cannot be undone, or that affect visitors, are marked with warnings, and they come before the commands.

Step 1 · Write down everything the old host does

A website is more than its files. List all of this before you build anything, because what you forget will stop working at cutover:

  • Files: the web root, uploads, and anything outside it (configuration files, certificates, cron scripts).
  • Database: type, name, user, and its size.
  • Web server configuration: virtual hosts, redirects, rewrite rules, PHP settings and limits (upload size, memory).
  • Scheduled jobs: cron entries and queue workers, which must run on exactly one server at a time.
  • Email: does the old host also host your mailboxes (MX records)? Moving a website does not move mail. Keep the MX records unchanged unless you are moving mail on purpose, and check your SPF record: if it lists the old server's address as a sender, add the new one.
  • Certificates: HTTPS certificates and how they renew.
  • Outside connections: services that allow only your old server's IP address, such as a payment provider, an API or a database firewall. They need the new address before cutover.
  • DNS records: A, AAAA, CNAME, MX and TXT for the domain and www. Export or screenshot them all.

Note the current TTL and address of your site. The number in the second column of the answer is the TTL in seconds:

Bash
dig +noall +answer example.com A
dig +noall +answer www.example.com

Replace example.com with your domain. A line such as example.com. 3600 IN A 203.0.113.10 shows a TTL of 3600, one hour. In these examples 203.0.113.10 is the old server and 198.51.100.20 is the new one; replace both with your own addresses.

Step 2 · Lower the TTL, and wait

Warning: this step must happen well before the move. Computers that have the old record cached keep it for the old TTL, so a lowered TTL only helps after the old, longer one has run out. If your TTL is a day, change it at least a day before.

In your DNS dashboard, edit the A record (and the AAAA record if you have one) for the root name and for www. Change only the TTL, not the address. Set it to 300 (five minutes). Some providers have a minimum of 60 or 300 seconds.

Then wait at least as long as the old TTL. Check by asking a public resolver that has not seen your record before, and watch the number count down and then reset to 300:

Bash
dig +noall +answer @8.8.8.8 example.com A

When the TTL shown starts from 300, not from the old value, the lowered TTL has reached the resolvers. Do not skip this wait. It is the whole reason the cutover can be quick.

Step 3 · Build the new host

Prepare the new server to serve the same site, without pointing anyone at it yet. Use the tutorials for the pieces you need: Nginx, a language runtime or PHP-FPM, a database such as PostgreSQL or MySQL, and the firewall. Match the old server's versions of the language and database as closely as you can. Changing the stack and the host in one move doubles the number of things that can go wrong, so save upgrades for after.

Configure the web server with the same domain names (server_name example.com www.example.com;) and the same redirect and rewrite rules. Keep cron jobs and queue workers switched off on the new server for now.

Step 4 · Copy the files

Copy from the old server to the new one with rsync, which sends only what changed, so you can repeat it. Run it on the new server, pulling from the old one, so the data travels directly between the two. The new server needs an SSH key that the old server accepts: log in with SSH keys shows how.

First do a dry run. -n shows what would be copied and changes nothing:

Bash
rsync -azn --info=stats2 -e ssh olduser@203.0.113.10:/var/www/example/ /var/www/example/

Read the output, then run it for real by removing the n:

Bash
rsync -az --info=progress2 -e ssh olduser@203.0.113.10:/var/www/example/ /var/www/example/

What the options do: -a keeps permissions and timestamps, and keeps owners only when it runs as root (otherwise files belong to the user you ran it as, so fix ownership afterwards), -z compresses in transit, and the trailing slash on the source path means "the contents of this folder". Without it you get a nested folder called example. Make sure the owner and permissions on the new server suit its web server user afterwards.

Warning: if you ever add --delete, which removes files on the destination that are not on the source, do a dry run with -n first and check the paths twice. A wrong destination path with --delete removes real files.

You will run the same command again at the cutover, to pick up the changes since this copy. It is fast, because only the differences move.

Step 5 · Copy the database

For a static site, skip this step. Otherwise, a dump and restore moves the database. Dumping and restoring a database that is in use gives a consistent copy only with the right options. For MySQL with InnoDB tables, --single-transaction takes a consistent snapshot without locking the site. Do not put the password on the command line: let mysqldump ask (-p with nothing after it), or use a ~/.my.cnf file with mode 600 on the server that runs the command. On the old server:

Bash
(umask 077; mysqldump --single-transaction --routines --triggers -u dbuser -p dbname | gzip > ~/dbname.sql.gz)

The dump holds everything in the database, including password hashes, so umask 077 makes the file readable only by you. Copy the file to the new server, with scp or rsync. Create the empty database and user on the new server as in the MySQL tutorial, and import. Enter the password when asked:

Bash
gunzip -c ~/dbname.sql.gz | mysql -u dbuser -p dbname

For PostgreSQL, the matching tools are pg_dump and pg_restore: see back up and restore PostgreSQL with pg_dump. For WordPress, back up and restore a WordPress site with WP-CLI does the file and database copy for you. A dump is a snapshot, and anything written to the old database after it is missing from the copy. The step that plans the cutover handles that.

When the import has worked, delete the dump from both servers with rm ~/dbname.sql.gz, after you have a proper backup elsewhere. Then update the site's configuration on the new server to use the new database: the connection details are in a config file such as wp-config.php or .env.

Step 6 · Test the new server before anyone uses it

Without touching DNS, make your own computer see the new server under the real name. curl --resolve does that for one request:

Bash
curl -sI --resolve example.com:80:198.51.100.20 http://example.com/ | head -n 1
curl -s --resolve example.com:80:198.51.100.20 http://example.com/ | head -n 20

For a browser, add a line to your computer's hosts file that maps the name to the new address: 198.51.100.20 example.com www.example.com. On macOS and Linux the file is /etc/hosts, on Windows C:\Windows\System32\drivers\etc\hosts. Remove that line when you are done testing, or you will forget why your computer behaves differently from everyone else's.

Click through the site as a user would. Log in, submit a form, upload a file, buy something in test mode, and look for broken images, wrong redirects, mixed content warnings and slow pages. Check the error log on the new server while you do.

HTTPS needs planning, because the usual certificate check (http-01) asks the domain's current address, which is still the old server. Two ways around it: copy the certificate and key from the old server to the new one over SSH and use them until the first renewal, or request the certificate with a DNS challenge, which proves ownership with a TXT record and works before the cutover: sudo certbot certonly --manual --preferred-challenges dns -d example.com -d www.example.com. Certbot tells you the record to add. For automatic renewal later, use a DNS provider plugin, or switch to the normal method after DNS points at the new server. See free HTTPS with Let's Encrypt and Nginx.

Add the new server's address to every allowlist on your "outside connections" list now.

Step 7 · Plan the cutover so no data is lost

For a static site, there is nothing to plan: sync once more and switch. For a site that takes input (orders, comments, sign-ups), choose how to avoid two live databases:

  • A short freeze (simplest). Put the old site into read-only or maintenance mode for a few minutes, take a fresh database dump, import it on the new server, run the file rsync once more, then switch DNS. Visitors see a maintenance page for a few minutes, not an outage of hours. Schedule it for a quiet time and tell people.
  • Old server forwards to the new one (smoother). After the final copy, make the old server pass every request through to the new server. Visitors whose computers still use the old address are served by the new server, with the one database. For Nginx on the old server, replace the site's location / with a proxy to the new address:
Nginx
location / {
    proxy_pass https://198.51.100.20;
    proxy_set_header Host $host;
    proxy_ssl_server_name on;
    proxy_ssl_name $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

With the two proxy_set_header lines the new server can see the visitor's real address in X-Real-IP and X-Forwarded-For, but only if it is set up to trust them from the old server (see set_real_ip_from in rate limit an API with Nginx). Without that, the new server sees every request coming from the old server's address, and per-address rate limits and logs treat all visitors as one. This requires the new server to have a working certificate for the domain and to run the site. Test it first with a spare name.

Whichever you choose, run the file rsync and the database dump once more after the freeze or forward starts, because that is the last moment when the old server changes.

Step 8 · Cut over

Warning: this step changes what the world sees. Do it only after the test step passed, the final copy is on the new server, and the TTL has been 300 for at least as long as the old TTL. Keep the old server running. Write down the old address, because it is your way back.

In your DNS dashboard, change the address of the A record to the new server's IPv4 address, for the root name and for www. If you have an AAAA record, change it to the new IPv6 address, or delete it if the new server has none. A forgotten AAAA record still sends IPv6 visitors to the old server, which is a classic cause of "works for me, not for them". Leave MX and email TXT records alone.

Then check straight away. Ask the authoritative nameserver first, which answers without caching, as in point a domain name at your website:

Bash
dig +short NS example.com
dig +short @ns1.example-dns.net example.com A

Replace the nameserver with one from the first command. Then ask public resolvers:

Bash
dig +short @1.1.1.1 example.com A
dig +short @8.8.8.8 example.com A

In five minutes or so, all should answer with 198.51.100.20. The one thing you cannot control is people whose resolver ignores TTLs and keeps old answers for hours, and this is why the old server stays on.

Step 9 · Watch both servers

For the next day or two, look at the access logs on both servers. Requests to the new server should rise, and requests to the old one should fall to nearly zero. On each server:

Bash
sudo tail -f /var/log/nginx/access.log

To tell the servers apart when you test, put a small file on each with the server's name, for example /server.txt, and fetch it with curl http://example.com/server.txt to see which one answered.

Check the things people forget:

  • Forms, logins, checkout and email from the site, on the new server.
  • Cron jobs: switch them on at the new server now, and switch them off at the old one. Two servers running the same schedule send duplicate emails and charge twice.
  • Email deliverability: mail sent from the new server's address must pass SPF. See set up SPF, DKIM and DMARC.
  • Monitoring and backups: point them at the new server, and make a first backup there.

If something is badly wrong, roll back: change the A record to the old address. It spreads as quickly as the move did, because the TTL is still low. This is the reason not to raise the TTL yet.

Step 10 · Raise the TTL and retire the old host

Wait until the old server has seen almost no traffic for a day or two, and at least as long as the old TTL has run, then:

  1. Raise the TTL back to a normal value such as 3600 on the A and AAAA records. A very low TTL for ever means more DNS lookups for your visitors and more load on your DNS provider.
  2. Remove the forwarding rule and any hosts-file lines you added.
  3. Take a final backup of the old server: files, database and configuration. Keep it somewhere safe for a few weeks.
  4. Remove the old server's address from allowlists, and stop services on it.
  5. After a week or two of calm, cancel the old hosting. Cancelling deletes the data and often cannot be undone, so only do this when the last backup is safe and the new site has been quiet.

Troubleshooting

  • Some visitors still see the old site after a day: their resolver or their router caches beyond the TTL. This is why the old server forwards to the new one, or at least keeps running, for several days.
  • The new site works by IP and not by name: the web server does not know the domain. Check server_name and the default site.
  • HTTPS errors only on the new server: the certificate is for the wrong name, or the new server has none. Check with curl -vI --resolve example.com:443:198.51.100.20 https://example.com/.
  • Data is missing after cutover: a write reached the old database after the dump. Compare the two and copy the missing rows, which is why the cutover needs a plan. Then move any remaining writes with the forwarding rule.
  • Duplicate emails or double jobs: cron or workers run on both servers. Stop them on the old one.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.