![]() |
Migrating WordPress from one web hosting company to another.
The goal is to have a blog installation which is active and working, and will never be disabled and cannot be damaged in any way, and to copy it to a new place. For my tests, I used an entirely new host using a new "practice" domain name.
- 1 Notes
- 2 Make a backup!
- 3 Overview
- 4 Use Softaculous
- 5 Entering maintenance
- 6 Set up a MySQL database on your new host
- 7 Download the files from your old host
- 8 Update your WordPress configuration basics
- 9 Uploading the files to your new host
- 10 Exporting from the WordPress SQL database from the old host
- 11 Importing the WordPress SQL database to the new host
- 12 Finishing touches
- 13 Troubleshooting and notes
Notes ∞
As always, read through and understand these notes completely before trying anything. These were made by and for a technically-minded person with some experience in related things, but none in this particular problem. Maybe you know a lot and just need a little hint, or maybe you are smart enough to follow along easily, or maybe you are completely lost and must go very slow. Just be careful.
My goal was to make sure everything worked fine before migrating the proper domain name.
When experimenting with a new domain name nobody knows about, you can take your time. However, when you're doing it for real you should aim to do it all very quickly so you don't lose comments or other information during your transition. There are fancy ways to do this seamlessly, but such ways are outside the scope of this tutorial. You will read that phrase a lot.
Make a backup! ∞
Your old host is important. You don't just want to be careful, you want to make backups. Perhaps you can do this manually, or perhaps your host's control panel has an easy way. If you aren't sure, ask your host before doing any of this. That way, if something bad happens (even if it's not your fault!) you can recover.
Furthermore, know how to restore backups. A backup is worthless if you can't, or don't know how to, do anything with it.
I was doing this whole process on an entirely new domain name so I can't mess up my existing installation.
Overview ∞
A general overview of the whole migration process.
WordPress has two parts:
- Files
A database
Files ∞
To access, upload and download files, you must refer to both your old host and your new host separately. FTP access is the most common.
No software recommendations, and no usage advice will be given. Refer to your two hosts' documentation.
For the advanced and security-conscious users, use SFTP or FTPS. You may also be able to Rsync over SSH, which I found vastly more simple than mirrorring using lftp.
A database ∞
Your old host ∞
For your old host, you need access to PhpMyAdmin for exporting. Maybe there's a simple "no login" way from your hosting control panel and you don't need to bother with a username or password.
No advice will be given on using an alternative to phpMyAdmin.
If all you can get is some sort of "database dump", then you're part-way through the process but will likely need to do more work to import it or have WordPress use it. Again, no instructions will be given. Some advice though: Pay attention to things like format (try to get UTF-8) and the database name. If possible, your table prefix should stay the same as it was at your old host, as I've had no success with my light attempt at changing this.
Ultimately, you will need to know how to export the database from your old host.
Your new host ∞
For your new host, you will need three things:
- Access to PhpMyAdmin for importing.
- A mySQL database-user
A mySQL database-password
You will likely not be provided any information until you pursue one of the steps in Set up a MySQL database on your new host.
No advice will be given on using an alternative to phpMyAdmin.
Use Softaculous ∞
Untested
If your new web host has provided Softaculous, then you can use it to install a new WordPress installation to your new domain name.
To do so, visit its wizard for a fresh WordPress installation. Now, instead of filling out the new-installation wizard look at the top for the tabs:
Install | Overview | Features | Screenshots | Demo | Ratings | Reviews | Import
Click Import
, then From Remote Server
, and fill in that information.
If this process works, then great! You have finished your import and can ignore the rest of this document.
Entering maintenance ∞
More advanced users with active websites can put their website into maintenance mode. This will temporarily lock it down so users can't access it.
To enter maintenance mode, create a file called .maintenance
in the root of your website.
I have no experience with this, and all it did for me was put a message at the top. Maybe it simply makes the website read-only.
Set up a MySQL database on your new host ∞
Pursue one of the following options. If one of them works for you, ignore the others.
Option 1 - Use a host-provided "one click install" ∞
Tested and works
This option will create a new WordPress installation which you will completely-overwrite with both your files and database import.
Many hosts have a wizard to create a brand new WordPress installation. This is recommended, because using such a wizard will probably initialize your host's automatic-update features. From what I can see, this seems to be cooked into WordPress itself so I wouldn't worry.
Do nothing to disable or delete the resulting WordPress installation.
Using such a wizard will also give you the mySQL database-name and mySQL database-user, perhaps by email. Note these. If you are not sent these, then you will have to pursue them in your host's control panel.
Note: It is okay to "break" this new-host WordPress installation by changing its database-user and database-password. Just record that login information for later use.
Option 2 - Use a database wizard ∞
Tested and works
This option will create a new empty database which you will completely-overwrite with your database import.
If one is provided, it's easy to use your new host's database wizard.
You want to record these three pieces of information:
A database
- Record its name
A database-user
- This will probably be different than your hosting control panel username.
A database-user-password
- This will probably be different than your hosting control panel password.
Technical Trivia: Many shared-hosting solutions will give no other way to create a database, because they force a database-name prefix.
Option 3 - Allow the phpMyAdmin import to create a database ∞
More advanced.
Download the files from your old host ∞
As they say, "this is left as an exercise for the reader".
Note: Always do a test/dry run before doing things for real.
With SSH and Rsync ∞
With LFTP ∞
Update your WordPress configuration basics ∞
Copy your wp-config.php
to back it up, then edit it to set these items.
The basics ∞
/** The name of the database for WordPress */ define('DB_NAME', 'your_database_name'); /** MySQL database username */ define('DB_USER', 'new_database_user_username'); /** MySQL database password */ define('DB_PASSWORD', 'new_database_user_password'); /** MySQL hostname */ define('DB_HOST', 'example.com');
DB_NAME
- You should already know this from Correct the database name.DB_USER
·DB_PASSWORD
- Your database is connected-to with its own user and password.- Maybe thay're what you used when logging into PhpMyAdmin.
- Maybe your host's WordPress quickstart set something up for you.
- Maybe you can explicitly check or set your database user's username and password in your web hosting control panel.
DB_HOST
- You need to check your web host's settings for this. Because I used a WordPress install helper, it created a valid installation for me. I could then check itswp-config.php
and re-use that setting.- If you used Softaculous to install WordPress, go to its WordPress installation page and look below for
Current Installations
. Edit your installation to getDatabase Host
. - Maybe it's something simple like
mysql.example.com
or evenlocalhost
.
- If you used Softaculous to install WordPress, go to its WordPress installation page and look below for
Uploading the files to your new host ∞
This is Download the files from your old host, but in reverse. You would be pushing your local files into your new host.
With SSH and Rsync ∞
With LFTP ∞
Exporting from the WordPress SQL database from the old host ∞
Note that if you know you have a large database, check the notes under Importing a large MySQL database. I had good success using Optimize Database after Deleting Revisions.
Using PhpMyAdmin
1. Change the format to SQL
Format: [SQL]
2. Change your "Export method", and set it to Custom
to reveal the additional options.
(_) Quick - display only the minimal options (*) Custom - display all possible options
3. Under Output
Compression: [zipped]
4. Under Object creation options
, set these two items:
Add statements: [x] Add CREATE DATABASE / USE statement [x] Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement
5. Scroll down and click Go
It'll begin a download of a zipped copy of your database.
Once downloaded, keep that file for your backups.
Make a copy called filename.zip
, and we'll refer to that name from now on.
Editing the WordPress SQL ∞
Both my old and new hosts automatically named their database. I was unable to directly export and then re-import the SQL, because the databases were named differently.
Perhaps you have good control of your new host's mysql, and you can create a new database with any name. You are lucky!
For me, I needed to manually edit my SQL.
Unzip the SQL file ∞
Something like:
\unzip filename.zip
Take the resulting file and rename it filename.sql
, and we'll refer to that name from now on.
Correct the database name ∞
You can look at your old host's PhpMyAdmin for the name, and you can also look inside the file you exported. You should see something like this:
-- -- Database: `your_database_name` -- CREATE DATABASE IF NOT EXISTS `your_database_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE `your_database_name`;
You want to change your_database_name
to the name that is appropriate for your new host.
To learn the appropriate name for your new host, visit your new host's PhpMyAdmin. You can look on the left, or if you go to its import page, the top should say something like:
Importing into the database "new_database_name"
Use your favourite editor to change only those three entries.
Warning: Do not do some sort of whole-file search-and-replace, or:
- It will take a very long time to go through the entire file.
You might change the contents. Maybe a plugin uses that phrase. Maybe one of your blog posts uses that phrase!
Note that you'll need a good editor that can handle a large file. Shell scripting could probably do this easily too, but I'm not going to bother with that.
Re-zip the file ∞
Something like:
\zip filename.sql.zip filename.sql
It does not actually matter what your SQL file or zip file are called.
Importing the WordPress SQL database to the new host ∞
Visit the PhpMyAdmin on your new host, go to Import
.
No settings need to be changed on this page.
Note: Look to see if there is a line that says something like (Max: 50MiB)
. Make sure your database is not this big. If it is too large, your import will probably fail. See importing a large MySQL database for some ideas, but I cannot help with this.
Under File to import:
, browse for your file. Then upload it.
It will take some time. This is good!
When it succeeds, you can visit your new domain name, but it will probably just send you to a WordPress installation screen. That's okay, we're not done yet!
Finishing touches ∞
1. If you have a .maintenance
file on your server, delete it.
- You can delete it from your local files, and re-synchronize only the changes, in much the same way you uploaded the files in the first place.
- or you can use your control panel file access interface, if you have one.
- or you can FTP/SFTP/FTPS in to do it.
or you can SSH in to do it, if you have access.
2. Test logging in, make sure your control panel has what you expect. It'll be something like example.com/wp-admin/
3. Test surfing.
Be sure to keep your backups. Disk space is cheap, keep your backups for as long as you can. If something happened to the SQL
You may have a broken theme or style. Check and update your theme, and check if you are using any custom CSS. Plugins which allow custom CSS are also a potential culprit.
4. Test wget and make sure you don't get a 500 error like this:
\wget example.com
HTTP request sent, awaiting response... 500 Internal Server Error
If you do have it, see White screen of death
5. Check your .htaccess file. If you changed hosts, you'll need to update it.
Check all plugins ∞
Some plugins have configuration that refers to your domain name. You'll need to update them.
Reinstalling plugins might also be necessary. See Broken references to your old website for easy instructions.
Check services ∞
CloudFlare and other external services will need to know about your new website.
Clear caches ∞
If you use any plugins that keep a cache, check their settings and clear them.
The BlogText plugin ∞
See Broken references to your old website
Troubleshooting and notes ∞
White screen of death ∞
https://codex.wordpress.org/Common_WordPress_Errors#The_White_Screen_of_Death
Check files ∞
Re-check that your files have been correctly uploaded.
Check wp-config.php
∞
Re-check your wp-config.php
and make sure its settings are correct.
In particular, check your DB_HOST
. It may not be the same as your website, there may be a specific URL, like mysql.example.com
or localhost
:
define('DB_HOST', 'localhost');
Update references to your old URL ∞
Your old installation likely has hard-coded references to your old site URL. See:
with wp-cli ∞
Installation:
\curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \php wp-cli.phar --info \chmod +x wp-cli.phar \mv wp-cli.phar ~/wp
Usage:
website='http://example.com' cd ~/public_html ~/wp option update home "$website" ~/wp option update siteurl "$website"
by hard-coding in wp-config.php
∞
You can also force your web page in your wp-config.php
by pasting two new new lines for WP_HOME
and WP_SITEURL
at the top of your wp-config.php
, like so:
<?php define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); /** * The base configurations of the WordPress. *
Table prefix ∞
See Setting your database's table prefix.
Thumbnails / resized images do not appear ∞
It's likely you didn't copy the thumbnails from your old server. This will save time/bandwidth, but now you need to regenerate them. I used:
https://wordpress.org/plugins/regenerate-thumbnails-advanced/
Setting your database's table prefix ∞
Setting your table prefix using Softaculous ∞
Just before launching its installation:
I've used the Softaculous Apps Installer. Under Advanced Options > Table Prefix
I've added the table prefix demanded by my previous host. Setting it as the same makes it easy to overwrite those tables during your import (See Importing the WordPress SQL database to the new host)
Renaming your table prefix using phpMyAdmin ∞
After importing your database:
- Click your database, on the left.
- At the bottom of the list, click
[x] Check all
To the right of it,
[With selected:]
change to[Replace table prefix]
and fill out your from/to.
(NOT WORKING) - Changing your table prefix post-install ∞
I thought you could update your wp-config.php
and then rename your table prefix, but it didn't work for me.
Your wp-config.php
will have:
/** * WordPress Database Table prefix. * * You can have multiple installations in one database if you give each a unique * prefix. Only numbers, letters, and underscores please! */ $table_prefix = 'your_prefix';
Broken references to your old website ∞
Reproduced with BlogText, but it's possible for other addons to have problems.
- Visit your plugins page:
http://example.com/wp-admin/plugins.php - Middle-click "view details", or right-click and open it in a new tab. Switch back to your plugins tab.
- Deactivate and then delete the plugin.
- Switch to the details page for the plugin.
- Refresh the page.
- At the bottom-right, click "install plugin".
At the bottom-right, click "activate plugin".