loading

Migrate WordPress

Introduction

WordPress stores the website's host name and the absolute paths to the sites files inside its database! This is a very unfortunate design flaw.

This means that if you change the website's host name and/or move the files somewhere else (locally, or to another server), you have to edit the WordPress database to reflect the changes.

Most web applications are immune to this requirement, because they are written to extract the web server's document root and the incoming HTTP Host Request header to dynamically determine where the files are, on disk.

Warning

Always have complete backups ready, in case disaster strikes.

Read EVERYTHING below, several times, before proceeding, including the Caveats section at the base of this article.

Prerequisites

The login credentials for source and destination web hosting & database accounts.

The source & destination document roots of the website.

The source & destination hostnames of the website, if different.

A copy of the latest version of the Search Replace DB utility.

Source & Destination Document Roots

When you move a WordPress website, either on the same server (from one web hosting account to another) or between different servers, the physical location of the website's files, on the server's disk, will almost always change. This change must be affected inside the database, on the destination database.

If you do not know the path to the document root, here's a method to find out.

Create a php script file with a random name (this is important for security reasons), containing the line below.

<?php echo getcwd(); ?>

Save that file inside the document root, at the same level where the main index.php file resides.

Example:

3u6dw9ct-find-docroot.php

Then, visit that script using your web browser:

Example:

https://example.com/3u6dw9ct-find-docroot.php

The script will print the absolute filesystem path, as experienced by the PHP environment on that particular web hosting account.

Repeat this process for both the source and destination hosts and record the details.

Example:

Source (old account): /var/www/user_abc/example.com/public_html
Destination (new account): /srv/web/w123/home/default/public

Source & Destination Hostnames/Paths

If the website's hostname or path is to be changed, you will also need to take note of and record those details.

It's important to include the HTTP scheme, whether http:// or https://

Example hostname change:

https://example.com -> https://example.net

Example path change:

https://example.com/blog -> https://example.com

Migration Steps

1

Take note of hostname and/or path changes between source and destination.

2

Determine source and destination document roots and paths for the old and new web hosting accounts respectively.

3

Archive (download) the source website.

4

Dump (backup) the source website's database to an SQL file.

5

Upload and the source website's files to the new web hosting account.

6

Import the source website's database into the new website's database, using the destination host's given control panel utilities, such as Adminer, or PHPMyAdmin.

7

Edit wp-confg.php on the destination host, changing it to use the new database name, username and password.

8

Download the latest version of Search Replace DB

9

On your own computer unzip the archive and rename the Search-Replace-DB-x.y.z folder to something random, like f8s4bhw7 - this is CRITICAL for security

10

Upload the renamed folder via SFTP or the hosting service's web based file manager, so that it resides within the destination web server's document root. This is typically public_html or public (as on our service).

11

Visit the location of the above script, on the new website. Example: https://example.com/f8s4bhw7

12

Most of the form fields will be auto-completed, since it reads wp-config.php for you.

13

For each of the changes required, fill in the replace and with boxes. Be sure to do this for the URL as well as the folder path to the document root.

14

First test with the dry run button to look for errors.

15

If error-free, repeat the above step, using the live run button instead.

16

Remove the folder f8s4bhw7 - this is CRITICAL for security

Caveats

If the WordPress site has the Yoast plugin enabled, you're advised to disable it on the source account first, before exporting it to be imported on the destination account. Only after running the search and replace script, should you re-enable Yoast.