This is a summary for migrating a WordPress instance from one hosting provider to another. If you are familiar with IT topics it’s something that is feasible. If not, better ask an expert for assistance since a weak setup is posing a big security risk for your site.
Prerequisites
You need to have some know-how to migrate WordPress:
- Basic MySQL / MariaDB CLI know-how.
- Linux command line know-how.
- Depending on your hoster also Apache know-how.
- SSH / SCP access towards your old and your new hosting server.
- MySQL / MariaDB host, user, password and database names of source and target hosting providers.
- Your domain / DNS data needs to be ready to be adjusted to point to the new host. If it is part of your source hosting providers contract, you’ll need to think about changing that.
Getting the settings from the source hosting
You can get the database coordinates from your source hosting by looking at the variables in the wp-config.php
file in your WordPress installation:
...
/** The name of the database for WordPress */
define('DB_NAME', 'xxx');
/** MySQL database username */
define('DB_USER', 'xxx');
/** MySQL database password */
define('DB_PASSWORD', 'xxx');
/** MySQL hostname */
define('DB_HOST', 'xxx');
...
These settings need to be also adjusted in the target hosting setup later on.
Transferring the MySQL / MariaDB database
The database contains the articles and settings of WordPress.
It can be dumped on the source host using a command like this:
mysqldump --host $HOST -u $USER --password=$PASSWORD $DATABASE | tee wp-dump.sql
after transfering this file to the target host, you can restore this file to the newly created database that eventually needs to be first created:
mariadb -u $USER --password=$PASSWORD $DATABASE <wp-dump.sql
In my case there were in the dump SQL users that were not existing in the target database. I needed to clean the SQL file from the user references with a grep:
grep -v $USERNAME wp-dump.sql > wp-dump-clean.sql
The WP Content directory
WordPress stores parts of its files and plugins in a filesystem folder called wp-content. You can back this up with the tar command on the source host:
tar -czvf wp-content.tar.gz wp-content
On the target host you can unpack this in the WordPress filesystem folder:
tar -xzvf wp-content.tar.gz
Database table prefixes
Please note that some installations use so called table prefixes,. This means that all database table names begin with a prefix string. In this case you need to
- prefix all table names in the next section with that string,
- configure your new wp-config.php to also use this string.
You can find out what prefix your database is using by
- looking at the
table_prefix
assignment of thewp-config.php
file from your source hoster or - looking at in the mysql / mariadb command line tool using
SHOW TABLES
.
Updating the site in the database
Depending on whether your site DNS name changes, you also need to update your WordPress database. You can access the following commands to update the locations:
update options set option_value='$SITEURL' where option_name='siteurl';
update options set option_value='$SITEURL' where option_name='home';