How to manually migrate a WordPress Website


In this article, we are covering a scenario where a website administrator has to manually migrate a WordPress Website from one server to another.

Specification:

WordPress Version: 5.4.2
OS Version: Ubuntu Os 18.04.3 (LTS) x64
MariaDB Version: 10.1.44

This process has 6 steps for a successful migration:

  1. Create server-mirror on a new location so migrated WordPress can still function
  2. Backup WordPress database
  3. Backup WordPress files
  4. Upload WordPress backup files to a new server (including database backup)
  5. Create a database on a new server and import backup of the old database
  6. Configure (if needed) WordPress installation on a new server

NOTE: Create server-mirror on a new location so that when we migrate a WordPress it can still function with all necessary dependencies. This process includes PHP support, Database server and other packages installed on the old server should exist on the new one.

Let’s move on!

Backup WordPress database

Login to the old server and execute the following command:

bluegrid-edu:~# mysqldump -uroot wpdatabase > /var/www/html/wpdatabase.sql

Backup WordPress files

Make sure to have zip installed before continuing as we want to pack the WordPress files into the .zip archive:

bluegrid-edu:~# apt-get install zip

Now navigate to document root directory and archive all the WordPress files:

bluegrid-edu:~#  cd /var/www/html/

Archive the WordPress files:

bluegrid-edu:/var/www/html# zip -r WordPress .zip ./

Upload WordPress backup files to a new server (including database backup)

We have created an archive within the document root directory of the old server. We should navigate to this location and prepare for upload to the new server:

bluegrid-edu:~# cd /var/www/html/

Now, using the below command we can upload the WordPress archive to the new server. The new server is on the domain new-server.bluegrid.io):

bluegrid-edu:~#  rsync WordPress.zip -Pav -e "ssh -i /path/to/ssh-key" ssh [email protected]:/var/www/html/WordPress.zip

And then just to unzip the archive in the new document root directory:

new-server.bluegrid.io:/var/www/html# unzip WordPress.zip

Create a database on a new server and import backup of the old database

  1. We are using MariaDB Server for this example so the next steps are following this premise. First, we need to create a database:
  • Login to MariaDB database server:
new-server.bluegrid.io:~# mysql
  • Create a database:
MariaDB [(none)]> create database wpdatabase;
  • Create a database user:
MariaDB [(none)]> create user [email protected] identified by 'wppassword';
  • Grant privileges to this user on the newly created database:
MariaDB [(none)]> grant all on wpdatabase.* to [email protected];
  • Reload privileges:
MariaDB [(none)]> grant all on wpdatabase.* to [email protected];
  1. Then we need to import old database backup to the new database. The database backup file was within the WordPress.zip archive. Now after we unzipped the Archive it’s in the document root directory /var/www/html/:
new-server.bluegrid.io:/var/www/html# mysql -uroot wpdatabase < wpdatabase.sql

That is about it! WordPress is migrated successfully with the same settings as it was on the old server. Enjoy!

Share this post

Share this link via

Or copy link