Contact me on Telegram Message

← All articles

How to Move a Website to New Hosting Without Downtime

There are many reasons to change hosting: a cheaper plan, a faster server, better support or a server in another country that the services you need can reach without problems. Moving the files isn't hard, but if you rush it, the website may stop opening for a few hours, and some requests or emails may get lost.

How to move a website to new hosting without downtime

The main principle of a move without downtime is simple: first fully set up and check the website on the new server, and only then switch the domain to it. Let's go through this plan step by step.


Preparation

Before moving anything, collect everything the website relies on on the old server:

💡 Tip: make a full backup of the website and the database before you start. If something goes wrong, you'll always have something to go back to.


Lower the TTL in advance

TTL is how long DNS servers and providers remember your domain's address. If the TTL is a day, after the IP address changes some visitors will keep reaching the old server for another day.

So a day or two before the move, lower the TTL of the A record (and AAAA, if there is one) to 5 minutes. You need to wait as long as the old TTL was — then by the time you switch, everyone will already know about the short TTL, and the new address will spread within a few minutes.


Moving files and the database

The easiest way to move files is an archive via the hosting panel or FTP. If you have SSH access to both servers, it's more convenient to copy them directly with rsync:

rsync -avz /var/www/example.com/ user@203.0.113.10:/var/www/example.com/

Here 203.0.113.10 is the new server's IP address. Export the database on the old server and import it on the new one:

mysqldump --single-transaction -u user -p database > database.sql
mysql -u user -p database < database.sql

The --single-transaction option makes a consistent copy of InnoDB tables without stopping the website. After importing, check the database connection settings in the website configuration: the database name, user and password on the new server are almost always different.

Don't forget to move the cron jobs and check file permissions: folders for uploads and cache must be writable by the website.


Checking before the DNS switch

This is the key step that makes a move without downtime possible. The domain still points to the old server, but you can open the website on the new one by setting its address just for your computer. To do this, add a line to the hosts file:

203.0.113.10 example.com www.example.com

On Windows the file is at C:\Windows\System32\drivers\etc\hosts, on Linux and macOS — /etc/hosts. Now your browser will open the website from the new server, while all other visitors still use the old one. You can also check the server's response without editing files using curl:

curl -I --resolve example.com:80:203.0.113.10 http://example.com

Go through the website: the home page, inner pages, forms, the admin panel, image uploads. Look at the PHP error log on the new server — that's usually where problems with the PHP version and extensions show up.

⚠️ Important: after checking, remove the line from the hosts file, otherwise your computer will keep opening the website at this address no matter what happens with DNS.


SSL certificate

The SSL certificate is where people stumble most often. A free Let's Encrypt certificate checks that the domain points to the server requesting it. But the domain still points to the old server, so issuing a certificate on the new one before the switch usually doesn't work. Options:

If the certificate isn't issued, sort out the error with the article "Let's Encrypt Certificate Not Issued". A common cause during a move is a www record that points not to the new server but, for example, to the registrar's parking page.


If data on the website changes

For a business card website with static pages, you can skip this step. But if the website receives orders, requests, comments or sign-ups, the data will change between copying the database and switching the domain — and the new records will stay on the old server.

To avoid this, right before the switch export the database once more and import it on the new server. And while switching, close forms and orders on the old server, for example by showing a short maintenance message.


Switching the domain

Once the website on the new server is checked, change the IP address in the A record in the DNS panel to the new one. Don't forget the AAAA record (IPv6), if there is one, and the www record. You can check that the changes have spread with dns.google or the dig command:

dig +short example.com A

⚠️ Important: don't turn off the old server right away. Some providers remember addresses longer than they should, and some visitors may keep reaching the old website for a couple of days.


After the move


Common problems


Summary

Collect everything the website relies on, lower the TTL in advance, move the files and the database, check the website on the new server via the hosts file and take care of the certificate. Only after that switch the domain, and keep the old server running for a few more days.

🚚 If you need help moving to new hosting, message me — I'll move your website without downtime.

Published

← All articles