It’s time, your WordPress Site gets a new domain or has to move to another server. I’ll explain how you can do this without any plugin and how the move works without any problems.
The problem with a domain change or a server migration are the URLs. WordPress stores absolute paths in the database that represent the main problem. That is, WordPress stores something like this in the database:
However, a better structure for a domain change would look like this:
For this WordPress would have to add a BaseURL in front of the path. This would look like this:
The Solution: Search-Replace-DB
Search-Replace-DB is a very good tool to easily rewrite these absolute links in the database.
If you just want to know how to use the tool and have already moved your database and WordPress files, you can jump directly to step 4. For all of you who want to migrate WordPress to another server, click here:
1. Moving Files and Database
First we have to move all files and the database to the new server. Therefore you should download all WordPress files via FTP and upload them to the target server. You can recognize the correct directory by the fact that there are folders like wp-admin, wp-content and wp-includes. Copy this complete directory to the new server in the target directory.
For advanced users: create a tgz archive and load it via curl to the target server and extract it to the target directory.
2. Export database
The database contains all data on pages, contributions, etc.. These data must of course be moved. For this we use the tool phpmyadmin, which you can download here. We simply put the unzipped folder into the main directory of the old site and can then call it via https://www.example.com/phpmyadmin and log in with the user data from wp-config.php.
The next step is to export the database. To do this, select your WordPress database and switch to the “Export” tab.
Type of export can remain on “Fast – show only necessary options” and format we also leave on “SQL”. With a click on “OK” we get a SQL file.
3. Import database
Well, who would have thought, we’d have to re-import the file on the target server. We load our phpmyadmin folder into the target directory and call it again. There we go to the “Import” tab and select our exported SQL file at “Select file”. We leave the remaining settings as they are and click on “OK”.
And already we have the database and all WordPress files on the new server and now we only have to take care of the actual “problem”.
4. Using the Search Replace DB correctly
We load the complete folder into the target directory and open it in the browser. The view will look like this and already reads the database access data automatically. If this is not the case, you can enter it manually and click on “update details”.
Now we enter the old and the new domain in the top line according to this scheme:
With a click on “dry run” we can display the changes. No data will be changed in this step! By clicking on “view changes”, we can display the changes and check whether the domain has been rewritten correctly.
If the domains have been converted correctly, we can click on “live run”.
Attention: Data in the database will be changed. This action cannot be undone!
If something should go wrong, this is not a problem, because we can simply import the previous database export again.
5. Check changes and delete tool
Finally you can check if you reach your page again and the conversion was successful.
Important: You should now delete the tool completely, so that nobody can mess with your database!
If you want to optimize your freshly moved site, you can check out these useful WordPress code snippets!