So, you finished your new WordPress creation, fresh theme is shining in your local development environment, site is full of awesome content. Everything is ready for a migration to production server/domain. But, how to migrate WordPress site properly?
There are plenty of guides and tutorials around the internet covering migration. They suggest plugins or manual search and replace in the database.
Both ways can help you, but as WordPress stores some of the content and data in serialized way, by search/replacing stuff through PhpMyAdmin can corrupt that serialized data and cause you a lot of headache.
I am going to show you a step by step way of migrating WordPress and the content safely and flawlessly to your production server.
Table of Contents
What is serialized data?
Serialization is a process of transforming data into a format that can be safely stored (in the memory, file or database) and can be later easily retrieved.
Serialization has become a standard in many programming languages. Problem with serialization is data portability. Let’s an example of serialized data:
[code lang=”php”]
a:2:{i:0;s:59:"C:\wamp\www\beta/wp-content/themes/twentythirteen/style.css";i:1;s:0:"";}
[/code]
As you can see, data is organized in a way that it has data types and number of elements in every data type. And that is the problem.
If you have something.home as your local development domain and somethingelse.com as production domain, they don’t have the same number of characters and if you search and replace domain in your database, you could get in trouble and corrupt your content data.
Migrate WordPress safely
1. Migrate files
First step of migration is to migrate all your files to production server. You can use FTP or SFTP or whatever method you see fit. After uploading files, open up your wp-config.php file and set database credentials.
2. Download and install Safe database search and replace tool
After that, go to WordPress search and replace database tool and download it. After you have done that, upload the file into the root of your production WordPress installation. You can rename it (so nobody evil can find it!) and you MUST delete it after you use it.
3. Migrate local database to production server
Go ahead, open up PhpMyAdmin (or another database tool of your choice) and export the whole database. Import it in your production server database.
4. Search and replace time
Point your browser to your production domain and the script for safe database search and replace. Then just follow the on screen instructions. In the first step, the script will ask you to pre-populate the database connection form with values from wp-config.php.
Leave that checkbox checked and press Submit.
On the next screen you can change database details (but it should be right if you correctly changed wp-config file) and submit.
On the next screen select all database table for scanning and press Continue.
Finally you get to the form in which you enter search and replace strings. After you hit the button, the tool will search and replace whatever you entered (so be careful).
EDIT: If you had WordPress install in a subdirectory locally, you need some additional steps, so read this article.
5. Test
Point your browser to production server domain and enjoy your new WordPress site with content and all. If everything works as expected, don’t forget to DELETE search and replace script!
That’s it, I hope that these tips will help you next time you try to migrate WordPress site to another server. Be sure to check some other tips on WordPress Codex.
Nice article, didn’t know about Search Replace DB, looks very handy. Thanks.
Duplicator plugin for wordpress does all this, and is easier and faster.
http://wordpress.org/extend/plugins/duplicator/
Thanks, Duplicator plugin really looks nice.
The thing is, that you can not use this plugin on multi site installation. And in the above method you can, you just select the correct database tables.
Also, @littleguy, a plugin is useless if you cannot get to the backend of WordPress.
@Zvonko thanks for the post.
Nice post. Easy and smooth. Don’t forget to refresh your permalinks on your new wordpress admin (Go to Permalinks and save settings).
Very interesting the point of “serialized data”. I didnt know it could get corrupted when you update info on the wp db… Thank You Zvonko.
Comments are closed.