Advice needed: Wordpress migration & test sites

I’m a designer with some development chops, mostly on the UI side. But I’m not really a strong developer or server admin type. I need some advice.

I now have a good dozen or so custom Wordpress installs that I set up and manage. Most of them are small business web sites, so I’m using WP as a CMS more than a blog.

My customers often request new features, or I may want to experiment with a new plugin or theme. So I need a test environment that mirrors the dev WP site, but is completely separate from it. I have not yet found an elegant way to do this.

Roughly, here’s how I currently migrate from test environment to production:

  1. Set up test subdomain ( on its own DH user account
  2. Install WP
  3. Build site at test subdomain
  4. Copy files from test subdomain to production user account
  5. Export sql from test
  6. Open sql file in text editor and massage it (removing test. subdomain and making whatever other tweaks necessary) > this is the hard and annoying part
  7. Import sql file to empty production database
  8. Check out the production site and realize a dozen things are broken, and pull my hair out

This is not a fun process, nor is it quick or highly successsful. And migrating back from production to the test subdomain so I can play around with some modifications… I can’t even figure out how to do that, because step 6 is too hard.

Ideas? Is there an elegant way to copy or migrate a Wordpress site to and from a test environment? Or am I looking at this the wrong way?

From my own experiences the database dump/backup of a wordpress database luckily doesn’t include any of the site’s configuration (aside from the title) so you can just do a straight import of the .sql backup in phpmyadmin or using the mysql cli.

When I have migrated any sites from testing to production typically I will make a backup of the prod folders and the database. Once that’s complete I copy over the existing site save for the wp-config.php. That way if there is a problem the rollback is just a directory copy and a sql dump restore.