Best practices for making a WordPress site “movable”?

Moving a WordPress website is fairly easy, here are the steps:

  • Backup your mysql database and re-import it in the new environment,
  • Move all the files to the new environment,
  • Update the wp-config.php file to reflect the new database connection information,
  • (*)Replace all occurrences of your domain name with the new one if it has changed

(*) This is the step that is confusing most of the time. People sometimes think it is enough to simply replace the few options in the database where the domain name appears but that is unfortunately not enough.

Indeed WordPress uses the PHP serialize/unserialize functions to store arrays in the the database. The problem here is that if you simply replace the domain name contained in a serialized object, you corrupt the data and will be unable to deserialize it because PHP serialization will add the length of every variable as part of the data. So unless you actually replace your domain name with another of the same size, you can not simply do a database search and replace.

Fortunately there are 2 easy solutions:

  1. This script: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
    You simply deploy the folder in the root of your install and access it over http. Do not forget to delete the folder once you are finished
  2. This CLI: http://wp-cli.org/commands/search-replace/
    Solution that I personally prefer because it does far more than just search & replace and can help you keeping a healthy WordPress instance.

Leave a Comment