I’m planning to buy a domain and install a WordPress site on it at a web-hosting company. But first I’ll need to iron-out some bugs… I got a working LAMP-stack at my home-computer, so I’m thinking about first installing my site locally – off the Internet.

I’ll be mostly tweaking and making “test-posts” to check that everything works, but I’ll probably also make some posts I’d like to keep when I move the site and take it online.

When I’m done chasing bugs; I guess I’ll just package the public_html|www directory-tree and upload it to the web-hosting company, and also export the database from my home-computer to the web-hosting.


What I’m wondering if there are some “best practices”, some do-s and don’t-s, some major pits to take note of?

For example, how can ensure the smooth transition of domain-name in posts and links as such, from localhost to whatever-i-end-up-buying.com (I know from previous attempt of running WordPress at my home computer, that this didn’t always work quite well…).

4 Answers
4

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 Reply

Your email address will not be published. Required fields are marked *