Module 9 · 9.5
English
Migrating a WordPress website
Module 9: Email, search visibility, GDPR, maintenance and migrating · Reading time: 10 minutes
Learning objective: 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 is switched at the end. Nothing needs to change in the database. - 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 need 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, then change the domain. That way, if something goes wrong, you'll know which step caused it.
And don't forget what sits alongside WordPress: email on the domain, DNS records, cronjobs, other websites in the same package. These don't move automatically (DNS course lesson 6.3).
Three ways to transfer the website
| Method | How | Watch out for |
|---|---|---|
| Installer import | Many installers (Installatron, Softaculous) can fetch a website from another server using the FTP or SFTP details of the old hosting | Fast, and the website is then immediately 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 files (SFTP or zip), export and import the database, adjust wp-config.php, search and replace for a new domain | Most work, but you see every step and it always works |
Doing it by hand works like this:
- Files: download the entire web directory (or make a zip of it via File Manager) and place 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? Search and replace the addresses with a tool that understands serialised data (lesson 3.2):
wp search-replace 'https://example.com' 'https://example.net' --all-tables --dry-run
wp search-replace 'https://example.com' 'https://example.net' --all-tables- Certificate on the new hosting (as soon as the DNS points there, or earlier if your hoster supports that).
Some hosters will migrate your website for you, free of charge or for a fee; WebOké offers this too. If so, ask which of the steps in this lesson they handle and which ones you need to check yourself.
Testing before the DNS switch
The most important principle of a migration without downtime: the new website already works before anyone visits 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 against your domain. Only your computer will then go to the new website. The certificate may not be valid there yet; only accept the warning for this test.
- A test address or preview from your new hoster, which shows your website under the real domain without changing the DNS (at WebOké, "Test your website before migration").
Go through the checklist from lesson 8.2: pages, images, logging in, forms, shop, permalinks.
Planning the switch
A few days in advance:
- Lower the TTL of the records you're going to change (A, AAAA, www) to, say, 300 seconds, so the switch becomes visible everywhere quickly later on (DNS course lesson 6.1). Do this at least the old TTL in advance.
- Make a backup of the old website (lesson 8.1) and keep it outside both hosters.
- Get mail ready if it's migrating too: create mailboxes, transfer mail, prepare MX records (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: choose a quiet moment and put the shop into maintenance mode briefly, otherwise orders will come in on the old website that you'll lose.
- Final sync: transfer the database (and any new uploads) from the old website to the new one one more time, so everything from the last few days is included.
- Switch the DNS: A and AAAA record (and www) to the new IP address. Remove an old AAAA record (lesson 2.1).
- Request a certificate on the new hosting as soon as the DNS points there.
- Check using this lesson's exercise and the checklist.
Afterwards:
- Leave the old hosting in place 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 show a 404), cache (clear it), cronjobs and WP-Cron (lesson 6.3), and mail from the website (lesson 9.1, SPF should now name 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're migrating 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. This keeps visitors from old links and preserves 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 (and a certificate on it) for years to come. Report the migration in Google Search Console using the change of address feature, and submit the new sitemap.
Summary
- Migrating to different hosting (same domain) and migrating to a different domain are different tasks; split them if you're doing both.
- Transfer the website using an installer import, a migration plugin, or by hand (files, database, wp-config.php, search and replace for a new domain).
- Test the new website before the DNS switch via the hosts file or a test address.
- Lower the TTL in advance, impose a content freeze, do a final sync, switch the DNS and check permalinks, cache, cron and mail.
- With a new domain: redirect every old address with a 301 to the same path on the new domain, and submit 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, for a domain change, the old domain as well. The tool checks: do the bare name and www (A and AAAA) point to the new server, is the certificate valid for both names, does the website's REST reference point to the right domain (siteurl converted correctly), does the old domain no longer appear in the links and sources of the homepage, and does the old domain (if provided) 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 do so now): which kind of migration, which transfer method, what needs to move alongside WordPress (mail, DNS records, cronjobs), how you'll test before the switch, the timeline (days in advance, the day itself, the days after) with who does each step, and how to roll back if something goes wrong. Tick off that 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 control panels; in other panels they work in a similar way.
- Importing a script 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
- 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/
