Move your website to a VPS without taking it offline

Visitors notice nothing if you migrate in this order: take inventory, lower the DNS TTL, copy files and database, test the copy through your hosts file, freeze editing, run a final sync, and only then change the A record. The old site keeps answering the whole time. Only editing and ordering pause, usually for minutes.

Updated:

The timeline at a glance

WhenActionCan you undo it?
A week beforeInventory, order the server, install the same versionsNothing has changed yet
2 days beforeLower TTL to 300, first full copyYes, freely
1 day beforeTest by hosts file, prepare the certificateYes, freely
Switch day, quiet hourFreeze, final sync, change the A recordYes, change it back
After reopening ordersWatch logs on both serversYes, but new data must be copied back
1 to 2 weeks laterRaise TTL, cancel the old hostingNo

Order the new server early. At Cloudraft the team checks an order before activating it, so this is not a task for switch night.

Inventory: what actually belongs to the site

  • Versions: web server, PHP or Node.js, database engine and version, PHP extensions. Moving to the same versions now and upgrading later keeps two kinds of problems apart.
  • Data: document root, uploads, database size, and files outside the web root such as .env.
  • Background work: cron jobs, queue workers, webhooks that call you.
  • Names: every DNS record, subdomains included. Export or photograph the whole zone.
  • Addresses: payment providers, banks and APIs that allow only your old IP. Ask them to add the new one now.
  • Mail: where the mailboxes live and how the site sends messages.

Disk and memory use on the old host tell you the size of the new one; how much RAM a VPS needs explains the reading. For a typical small site the choice is between these two:

  • Starter₼19.90/mo

    1 vCPU · 2 GB RAM · 30 GB NVMe

    Public IP +₼10/mo, With public IP: ₼29.90/mo

  • Standard₼39.90/mo

    2 vCPU · 4 GB RAM · 60 GB NVMe

    Public IP +₼10/mo, With public IP: ₼49.90/mo

Prices in manat (AZN), billed monthly. The public IP is +₼10 a month and is assigned automatically.

Lower the TTL first

Ask one of the domain's own name servers for the current value (second column, in seconds); an ordinary resolver shows only the time remaining. Then set the A records of the domain and www to 300:

dig +short example.com NS
dig +noall +answer @ns1.example.com example.com A

Wait at least as long as the old TTL before switching. If it was 86400, that is one full day.

Copy files and database

Run this on the new server; 198.51.100.20 is the old one. Mind the trailing slashes.

sudo apt install rsync
sudo mkdir -p /var/www/example.com
sudo rsync -aHz --info=progress2 olduser@198.51.100.20:/home/olduser/public_html/ /var/www/example.com/
sudo chown -R www-data:www-data /var/www/example.com

No SSH on the old hosting? Download an archive from its control panel instead. For MySQL or MariaDB, make the dump on the old server:

mysqldump --single-transaction --quick --no-tablespaces --triggers \
  --default-character-set=utf8mb4 -u shop_user -p shopdb | gzip > shopdb.sql.gz

--single-transaction gives a consistent copy without locking, but only for InnoDB tables. Check for others, and dump during the freeze if you find any. Add --routines --events if the site uses stored procedures or events.

mysql -u shop_user -p -e "SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA='shopdb' AND ENGINE<>'InnoDB';"

On the new server (Debian 12 packages MariaDB, Ubuntu offers both), create the database and import:

scp olduser@198.51.100.20:shopdb.sql.gz .
sudo mysql <<'SQL'
CREATE DATABASE shopdb CHARACTER SET utf8mb4;
CREATE USER 'shop_user'@'localhost' IDENTIFIED BY 'choose-a-long-password';
GRANT ALL PRIVILEGES ON shopdb.* TO 'shop_user'@'localhost';
SQL
gunzip -c shopdb.sql.gz | sudo mysql shopdb

Stay on the same engine. The error Unknown collation: utf8mb4_0900_ai_ci means a MySQL 8 dump is being loaded into MariaDB. Update the database settings in the site, and leave cron disabled on the new server so customers do not get every message twice.

Test before the world sees it

Point only your computer at the new server. Add this line to /etc/hosts (macOS, Linux) or C:\Windows\System32\drivers\etc\hosts (Windows, as administrator):

203.0.113.10 example.com www.example.com

Restart the browser and go through the login, search, a form, an upload and a test order. From the command line no edit is needed:

curl -kI --resolve example.com:443:203.0.113.10 https://example.com/

The certificate must exist before the switch. Either copy the current certificate and its key, or prove ownership with a TXT record:

sudo certbot certonly --manual --preferred-challenges dns -d example.com -d www.example.com

A manual certificate does not renew itself. Once DNS has changed, replace it as described in the nginx and SSL guide. Remove the hosts line when you finish testing.

Freeze, final sync, switch

  1. Choose a quiet hour and tell editors to stop. Put a shop in maintenance mode or close checkout; a brochure site needs no freeze.
  2. Stop cron jobs and workers on the old server.
  3. Repeat the file copy. Try rsync -aHzn --delete --itemize-changes first to see what would be deleted, add --exclude for files that differ on purpose, such as configuration, then run it without n and repeat the chown.
  4. Make a fresh dump and import it again.
  5. Open the site through the hosts file once more and check the latest order or article.
  6. Change the A records of example.com and www to 203.0.113.10. Delete an AAAA record if it points to the old host.
  7. Start cron on the new server and end the maintenance.

Some resolvers keep the old answer longer than they should. If you control the old web server, forward the stragglers so that nobody writes to the old database:

location / {
    proxy_pass https://203.0.113.10;
    proxy_ssl_server_name on;
    proxy_ssl_name example.com;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Where you cannot do that, leave the old copy in maintenance mode.

Mail: the part people forget

Change only the A records of the website. MX, SPF, DKIM and DMARC stay as they are unless mail moves too. Three traps:

  • The record mail.example.com may be an alias of the domain; after the switch it would follow the site. Give it its own A record with the old address first.
  • If the site sends mail itself, the new IP must be in the SPF record. Sending through an authenticated SMTP account is more reliable.
  • Cancelling the old package deletes its mailboxes. Move them beforehand, for example with imapsync to business email.

Changing name servers on the same day multiplies the risk. Recreate every record at the new DNS provider and do that on a different day.

Rollback plan

Decide in advance what makes you go back, such as failing payments for 15 minutes. Before orders reopen, going back means restoring the old A record, and the low TTL makes that quick. After that the new database holds the truth: freeze again, dump it, import it on the old server, and only then change DNS. Keep the old hosting untouched for two weeks, take a backup outside the server, and set the TTL back to 3600 when everything is quiet.

Migration questions

How long does it take to move a website to a VPS?

A small site takes an evening of work plus a day of waiting for the old TTL. The moment visitors move is the DNS change, which with a TTL of 300 reaches most of them within minutes.

Will I lose Google rankings after changing the server?

Not if the addresses, content and HTTPS stay the same and the site remains reachable. Crawlers simply follow the new IP. Compare response time and 404 errors for a week.

Can I migrate without SSH access to the old hosting?

Yes. Export the files as an archive and the database through phpMyAdmin or the control panel, then upload both. The final sync takes longer, so plan a longer freeze.

Do I have to move my email together with the website?

No. Mail follows the MX records, the website follows the A records. Leave the MX records alone and the mailboxes stay where they are, as long as that service remains paid.

Read next

All VPS pages

This page in other languages: Azərbaycanca · Русский · Türkçe

Servers in Baku, prices in manat

Create an account, top up your balance and order the plan you need.