In a previous post I have described the possible ways of migrating WordPress. For the manual ways of moving your website to another hosting and domain there might be some potential problems with the database entries. In other words – something might go wrong due to the fact that the URL structure and domain information that is stored in the database will be different than the actual situation.
In this post I will show you how to place things in order in case of such problem. You will learn how to achieve the final migration touches for the WordPress database with the plugin Search&Replace.
What does Search & Replace do?
The name gives a tremendous hint – you can search your database tables for the old domain name and replace it correctly with the new one.
But that is just one of the things that Search&Replace can provide for you. When you download, install and activate it you can go to Tools -> Search&Replace and then you will see 5 tabs. Let’s review all of them individually:
The first tab is called Backup Database.
There is a single button called “Create SQL File”. Click on it and you will get a SQL export of your WordPress database which you can keep for backup purposes. This file will be available for download via a newly created button with text “Download SQL File” which will be under a message that informs you of the successful export of the database.
The second tab is called Search & Replace.
Here is the actual reason why you’d want to have this plugin installed and activated in the first place. In order to make the magic happen you have to enter the old domain name exactly as it was with http:// in front and www if you have used it. Below this field you have to enter the new domain in the same matter.
Then you need to select the database tables that you want to be searched and replaced with the new domain name. You may choose some of them but for migration purposes you need to use all of them. So instead of selecting them one by one you can simply click on the checkbox “Select all tables”.
Next you can make a Dry Run and this option is enabled by default. This is to ensure that the plugin works. For actual Search and Replace of the domain name you need to disable this. By doing so two radio buttons will become active. One of them allows you to make the changes and then export a SQL file. The other option is to make direct changes to the database. In case you choose the first option you will need to re-import this file in the database for your WordPress website in order to make the needed changes.
You can also use GZ compression for the database if needed.
When you make up your mind you need to click on the button “Do Search & Replace”. You will be presented with the results of the operation and in most cases it should be successful. At least I did not have any problems for now when using this method.
The next tab of the plugin is called Replace Domain URL.
Here you can replace the domain name in general and you can also change the database prefix if needed. For our purposes you might not need to use this tab at all.
The next one is called SQL Import.
In it you can import a SQL File and thus apply changes to the database. In our current situation I’d advise you to use PHPMyAdmin or other tool just to be on the safe side.
The last tab is called Credits.
Here you will be able to see information about the plugin.
How to achieve the final migration touches for the WordPress database?
First make sure that your website is accessible after the migration. You will need access to the WordPress admin panel. If this is not possible you will need to open PHPMyAdmin or other tool that is provided by your hosting provider and make some changes in the wp_options table. Change the domain name for siteurl and home.
Then edit your wp-config.php and add the following two lines at its end:
define(‘WP_HOME’, ‘http://new domain name’);
define(‘WP_SITEURL’, ‘http://new domain name’);
Make sure that you add your new domain name in by replacing http://new domain name. Save the file and then try to access the login page of your WordPress website. You should be successful. If not – check the PHP version of the new hosting and change it to a version that you know is supported by your website.
Now you should be able to access the admin panel. Install and activate the Search&Replace plugin and then make the needed changes by using the Search & Replace tab. You are done and in most of the cases you will be successful!
Another way is to have the plugin installed and activated on the old hosting and domain name so that it will be instantly available for the new ones. You can also download the plugin ZIP file manually and extract it to wp-contents/plugins. By doing this you will be able to instantly activate it when you get access to the admin panel after the migration.
What else should you do in order to prevent potential problems?
First of all make sure that you have a backup of your database before using Search&Replace. This is extremely important! You may not encounter any problems but a backup needs to be present in case you are not so lucky. So to be on the safe side – make sure you have one!
What if Search&Replace does not replace everything 100% correctly?
Contact the plugin developers and ask for support.
That’s all folks! What do you think of this plugin? Share any thoughts and questions in the comment section below.
See you soon, friends!