Migrating WordPress Websites [2012]


Over the past two years I’ve found some improvements to my process, most notably around serialized arrays.

Migration Process

  1. Backup the database tables. I like to use Sequel Pro to connect to my database and export them, but you can also use the Adminer WordPress plugin or phpMyAdmin through your server’s cPanel. The default export will the a .sql file, but you might want to use one of the compressed formats. Many hosts only allow you a small file upload (like 2MB), and compressing it can help you stay under that limit.
  2. Backup the wp-content directory. This can be as easy as FTP’ing onto your server and dragging a copy of wp-content/ to your computer. If you have SSH access and are comfortable with command line, I like to make a tarball because it is much faster to download than a lot of small files. Use a command like this: tar -pvczf wp-content.tar.gz wp-content/.
  3. Upload the database to the new server. If WordPress is already installed, use the Adminer plugin to add the database. If not, you might use phpMyAdmin provided by the host. If you’re migrating to a server that’s already running WordPress, it’s a good idea to create a new database and upload the new tables there. That way, if something goes wrong you can quickly switch back to the old site. If you’re limited to one DB, you can also use a different table prefix (here’s how to change the table prefix of your new tables).
  4. Upload searchreplacedb2.php to the top level of your server (wherever wp-config.php is). This is used to find all the uses of the old domain and replace them with the new domain. The reason we’re using this tool instead of simply doing it in the database is that it will work with serialized arrays. Click the above link to read more about the problem and solution. If you’re really worried about security, do this locally or on your development server so that this file never has to be on the production server. If your server has WP CLI installed, you can use the wp search-replace command instead of this script.
  5. Load the the search and replace tool at http://www.yoursite.com/searchreplacedb2.php. It will auto-populate the database information from wp-config.php. Click “Next”, select the applicable tables, then on the find/replace screen type the old and new domain. Make sure you do not include a trailing slash (correct = http://www.yoursite.com | incorrect = http://www.yoursite.com/). Do the find and replace, then remove this file from your server.
  6. If a brand new website, upload copy of WordPress along with your custom wp-content directory. If there’s already a WordPress website live, follow the rest of the steps below.
  7. If you’ve downloaded the wp-content folder to your computer, rename the folder wp-content.new. Or if you pulled the tarball over, unpack and name it wp-content.new. The name doesn’t matter, it just has to be different than wp-content. Upload the folder to the same directory that has the old wp-content/ .
  8. Open wp-config.php. Update the DB information and $table_prefix if they have changed.
  9. Save wp-config.php, and then immediately rename wp-content/ to wp-content.old/, and wp-content.new to wp-content/
  10. Check the website’s homepage. If anything looks wrong, switch to the old site while you figure it out. Go into wp-config.php, comment out the new table prefix and remove the commenting on the old table prefix. Rename the wp-content directories back to how they were.
  11. If the site is working, log in and go to Settings > Permalinks, then click Save. This will update the permalink structure and ensure all URLs work.
  12. Go to Settings > Privacy and make sure you have the site visible to search engines.
  13. On the old site, install the Migration Notice plugin. I’ve had a lot of clients get confused about which backend they are supposed to post new content to, so if you aren’t deleting the dev environment immediately this prevents that issue.
  14. Make sure you’ve removed searchreplacedb2.php. This was mentioned in #4, but deserves reiterating (thanks WPExplorer).
  15. Update file permissions of wp-content directory. If you’re using WPEngine, they’ve added a super useful button “Reset File Permissions” in their WPEngine page of your WordPress backend.

Post a Comment

0 Comments