Module 9 · 9.5
Migrating a WordPress website
Module 9: Email, search visibility, GDPR, maintenance and migrating · Reading time: 10 minutes
Learning goal: After this lesson you can migrate a WordPress website to different hosting or a different domain without downtime.
Key concepts: migrating to different hosting, migrating to a different domain, installer import, migration plugin, migrating by hand, search and replace, testing before the DNS switch, hosts file, TTL, content freeze, final sync, checks after the switch, change of address in Search Console
Two kinds of migration
There are two kinds of migration, and they are different:
- To different hosting, same domain. The website moves from server A to server B; the address stays
https://example.com. The DNS changes at the end. Nothing in the database needs to change. - To a different domain. The website moves from
example.comtoexample.net(on the same or different hosting). All addresses in the database change, and you have to redirect the old domain.
Sometimes you do both at once. If so, it's best to split them: first migrate to the new hosting, and only then change the domain. That way, if something goes wrong, you know which step caused it.
And don't forget what sits alongside WordPress: email on the domain, DNS records, cron jobs, other websites in the same package. They don't migrate automatically (DNS course lesson 6.3).
Three ways to transfer the website
| Method | How | Caution |
|---|---|---|
| Installer import | Many installers (Installatron, Softaculous) can fetch a website from another server using the FTP or SFTP details of the old hosting | Quick, and the website then appears straight away in your installer (lesson 2.2) |
| Migration plugin | A plugin creates a package (files and database) on the old website and places it on the new one, often converting the addresses as well | Some free versions have a maximum size; large uploads can run into timeouts |
| By hand | Copy the files (SFTP or zip), export and import the database, edit wp-config.php, and with a new domain, search and replace | Most work, but you see every step and it always works |
By hand, it works like this:
- Files: download the entire web directory (or make a zip of it via File Manager) and put it in the web directory on the new hosting.
- Database: export it on the old hosting (phpMyAdmin or
wp db export), create an empty database with its own user on the new hosting (lesson 2.3) and import it (lesson 8.2). - wp-config.php: enter the new database name, user, password and host. Check the table prefix.
- New domain? First make a backup of the database (or use the export from step 2). Then search and replace the addresses with a tool that understands serialised data (lesson 3.2): first the trial run with
--dry-run, then the real one.--skip-columns=guidleaves the permanent identifiers of Posts alone, and without--all-tablesWP-CLI sticks to the WordPress tables.
wp search-replace 'https://example.com' 'https://example.net' --skip-columns=guid --dry-run
wp search-replace 'https://example.com' 'https://example.net' --skip-columns=guid- Certificate on the new hosting (as soon as the DNS points there, or earlier if the host supports it).
Some hosts will migrate your website for you, free or for a fee; WebOké offers this too. If so, ask which of the steps in this lesson they carry out and which you need to check yourself.
Testing before the DNS switch
The key principle of a migration without downtime: the new website already works before anyone goes to it. You test it on the new hosting while the DNS still points to the old one. Two ways (lesson 2.1):
- The hosts file on your own computer: add the IP address of the new server next to your domain. Only your computer will then go to the new website. The certificate may not be there yet; accept the warning for this test only.
- A test address or preview from your new host, which shows your website under the real domain without changing the DNS (at WebOké: "Test your website before migration").
Work through the checklist from lesson 8.2: Pages, images, logging in, forms, shop, permalinks.
Planning the switch
A few days before:
- Lower the TTL of the records you're going to change (A, AAAA, www) to, for example, 300 seconds, so the switch is quickly visible everywhere later (DNS course lesson 6.1). Do this at least as long beforehand as the old TTL.
- Make a backup of the old website (lesson 8.1) and store it outside both hosts.
- Prepare the email if that's migrating too: create mailboxes, transfer email, have the MX records ready (DNS course lesson 6.3).
On the day of the switch:
- Content freeze: from now on, nothing changes on the old website. For an online shop: pick a quiet moment and briefly put the shop into maintenance mode, otherwise orders will come in on the old website and you'll lose them.
- Final sync: transfer the database (and new uploads) from the old website to the new one once more, so everything from the last few days is included.
- Switch the DNS: A and AAAA records (and www) to the new IP address. Remove any old AAAA record (lesson 2.1).
- Request a certificate on the new hosting as soon as the DNS points there.
- Check with this lesson's exercise and the checklist.
Afterwards:
- Keep the old hosting for a few more days (with the website in maintenance mode or read-only), for visitors who still have the old address cached, and as a fallback.
- Check permalinks (save once at Settings > Permalinks if Pages return a 404), cache (clear it), cron jobs and WP-Cron (lesson 6.3), and email sent from the website (lesson 9.1: SPF must now include the new server).
- Raise the TTL again.
- Only after a week or two: cancel the old hosting, after downloading one last backup.
With a new domain: redirecting
If you migrate to a different domain, the old domain must stay in place and redirect: every old address with a 301 to the same path on the new domain (https://example.com/contact/ to https://example.net/contact/), not everything to the homepage. That way you keep visitors from old links and your position in search engines (lesson 9.2).
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ https://example.net/$1 [R=301,L]Keep the old domain (with a certificate on it) for years. Report the migration in Google Search Console using the change of address tool, and submit the new sitemap.
Summary
- Migrating to different hosting (same domain) and to a different domain are separate jobs; split them if you do both.
- Transfer the website with an installer import, a migration plugin or by hand (files, database, wp-config.php, and with a new domain, search and replace).
- Test the new website before the DNS switch via the hosts file or a test address.
- Lower the TTL in advance, hold a content freeze, do a final sync, switch the DNS and check permalinks, cache, cron and email.
- With a new domain: every old address with a 301 to the same path on the new domain, and a change of address in Search Console.
Quiz
Exercise
Exercise A9.5: Did the migration succeed? After a migration, enter your domain, the IP address (or server name) of the new hosting, and with a domain change, the old domain as well. The program checks: do the bare domain and www (A and AAAA) point to the new server, is the certificate valid for both names, does the website's REST link point to the correct domain (siteurl converted properly), does the old domain no longer appear in the links and resources of the homepage, and does the old domain (if entered) redirect with a 301 to the same path on the new one?
Exercise D9.5: Your migration plan. Write a plan for migrating your own website (even if you're not planning to right now): which kind of migration, which transfer method, what needs to come along besides WordPress (email, DNS records, cron jobs), how you'll test before the switch, the timeline (days before, the day itself, the days after) with who does each step, and how you can roll back if it goes wrong. Tick the box to confirm you've looked up the current TTL of your A record, and note it down.
Exercise D9.5: Your migration plan
You do this exercise yourself; no one checks it. Tick off what you've done and mark the exercise as done.
Lower the TTL a few days in advance, agree on a content freeze with a final sync just before the switch, and don't forget email and the other DNS records.
Your ticks and notes only stay in this browser; we don't send them anywhere. If you're signed in, we only save in My courses that you've done the exercise.
Further reading
These articles describe the steps in WebOké's panels; other panels work in a similar way.
- Importing an existing website into Installatron
- DirectAdmin guide 13.4: Importing an existing website into Installatron
- My website isn't working after uploading or moving it
- Moving your domain, website and email together without downtime: the step-by-step plan
- DirectAdmin guide 18.8: Testing my website before the domain has moved
- WebOké manual 14.2: Testing your website before a move
- Search and replace in the WordPress database
- DirectAdmin guide 12.4: Exporting a database
- Free DNS course 6.3: DNS during a transfer
- Migrating WordPress (developer.wordpress.org, English): https://developer.wordpress.org/advanced-administration/upgrade/migrating/
- Migrating WordPress manually: files, database and wp-config.php
