How to use a testing server with wordpress

March 1st, 2009

I like to mirror and build my wordpress site on a testing server and get it all ‘just right’ then push the changes to production when I’m somewhat ready to release. This a standard practice in the IT industry and gives us the advantages of

  • the site is never in a half-baked or broken state
  • development is super responsive since the server is on our local network
  • the site statistics don’t get polluted by the traffic of development
  • we can try new things without worrying that we’ve broken the website
  • we have a backup which is active and recent

But, because wordpress is not built with any anticipation of this concept, some problems arise

  • How to pull fresh comments and posts from production to testing?
  • How to push new and updated posts from testing to production?
  • How to handle images and media attached to posts?
  • How to handle site configuration options?
  • How to handle Theme changes?

Today we’ll tackle the easiest of these problems…

How to pull fresh comments and posts from production to testing?

  1. Export the content using the Wordpress ‘export’ function
  2. Delete existing content from the test server (optional)
  3. Import the content using the Wordpress ‘import’ function
Export the content using the Wordpress ‘export’ function

What could be simpler?

  1. Login to the site administration
  2. Comments->Spam->Delete All Spam
  3. Tools->Export
  4. Download->Save As
Delete existing content from the test server (optional)

Wordpress’s import function takes a very conservative view of the incoming content which is bit of a nuisance for our purposes.

  • It will only import new pages and posts
  • It will not update any changed pages/posts
  • ‘Draft’ posts will be duplicated on every import

So to make that clear: the import routine will add any post which does not already exist, and when a post does already exist it will not update the existing post with the import version. This creates a problem if we’ve edited a post in production and want that edit copied to testing.

The solution is to delete all the content on testing before you import. This sidesteps the problem and are concrete that testing is a true mirror of production. Sadly it destroys any edits done in testing that haven’t made their way to production yet. So things can get a little prickly since we prepare content on testing whilst people are adding comments, or if any post editing is done directly on production.

I’m quickly coming to the conclusion that I must refrain from editing or posting on production. If I really want to see the latest comments on testing then I’ll show how to migrate them from the database with SQL on another day.

Anyway to delete the content of a wordpress database you need to run this SQL statement using a mysql client. I use phpMyAdmin:


TRUNCATE `wp_comments` ;
TRUNCATE `wp_postmeta` ;
TRUNCATE `wp_posts` ;
TRUNCATE `wp_terms` ;
TRUNCATE `wp_term_relationships` ;
TRUNCATE `wp_term_taxonomy` ;

Now there can be no conflict and we can be sure the testing content mirrors production exactly.

Import the content using the Wordpress ‘import’ function
  1. Login to the site administration
  2. Tools->Import->Wordpress
  3. Browse->Upload
  4. map to existing - bit of a nuisance it doesn’t default to this every time
  5. Try the “Download and Import” and see if it works for you. It doesn’t for me; so images with wordpress are a mess which I hope to deal with in a later post.
  6. Submit

There are some more important things to note here.

  1. it won’t work if you have a lot of content as the files will get too big to handle
  2. it will not copy over any configuration settings, links, or users.
  1. No comments yet.
  1. No trackbacks yet.