How to move a WordPress site to a new host

Copy the files and database, test on the new server before anyone else sees it, then switch DNS with the old host kept as your way back.

2–3 minutes
Assorted laptop and desktop hard drives

A WordPress site is two things: a folder of files and a MySQL or MariaDB database. Moving it means copying both, connecting them, testing, and only then pointing the domain at the new server. Done in that order, visitors never see a broken site and the old host stays as your way back.

You need: SSH or file access to both servers, an empty database and user on the new server, and access to your DNS. This guide uses WP-CLI; each step notes the alternative.

1. Lower the DNS TTL a day early

Set your domain’s A record TTL to 300 seconds at least as long before the move as the current TTL. When you switch later, the change spreads in minutes. See DNS propagation.

2. Export the database and pack the files

On the old server, in the folder that contains wp-config.php:

wp db export ~/site.sql
tar czf ~/site-files.tar.gz -C "$(pwd)" .

Without WP-CLI, use mysqldump -u DB_USER -p DB_NAME > ~/site.sql with the values from wp-config.php, or phpMyAdmin’s Export tab. From now until the move is done, avoid publishing or changing content.

3. Copy both to the new server

From the new server:

scp olduser@old.server.ip:~/site.sql olduser@old.server.ip:~/site-files.tar.gz ~/
tar xzf ~/site-files.tar.gz -C /var/www/example.com/public

4. Connect WordPress to the new database

cd /var/www/example.com/public
wp config set DB_NAME new_db_name
wp config set DB_USER new_db_user
wp config set DB_PASSWORD 'new-db-password'
wp db import ~/site.sql
sudo chown -R www-data:www-data /var/www/example.com/public

www-data is the web server user on Debian and Ubuntu; use your server’s.

Changing the domain too? WordPress stores full URLs in the database, some inside serialized data that plain find-and-replace corrupts. Use WP-CLI, with --dry-run first:

wp search-replace 'https://old-domain.com' 'https://new-domain.com' --skip-columns=guid --dry-run

5. Test before anyone else sees it

Point the domain at the new server for your computer only by adding a line to your hosts file (/etc/hosts on macOS and Linux, C:\Windows\System32\drivers\etc\hosts on Windows):

203.0.113.10  example.com www.example.com

Flush your DNS cache, then log in, open posts, submit a form and check images. Expect a certificate warning until the new server has one. Remove the line when finished.

6. Switch DNS and add the certificate

Change the A record (and AAAA) to the new IP. Once dig example.com +short shows it, issue a certificate. See free SSL with Let’s Encrypt.

Leave the MX records alone unless you are moving email too.

7. Keep the old host for a few days

Some visitors reach the old server until their resolvers catch up. Keep it running for at least 72 hours and check it for comments, orders or form entries that arrived during the switch. Then take a final backup, cancel it, and set the TTL back to 3600.

Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.