How to Restore a wordpress backup on another host

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

Suppose you have a full backup (with database and files) of a wordpress site (say of example.com).  Now you want to restore this wordpress backup on a different host (say to example.net).   You might have to do this is for some reason if the current site (example.com) is broken and you want to debug the site on a subdomain or on a different host (such as example.net for the purpose of this tutorial).

You can not simply upload the files and import the database.  The host url are different and these are referenced in the wp-config.php and in the database backkup sql file.  If you are migrating or cloning a wordpress site from one host to another, there are wordpress plugins that helps you change and update these references.

However, suppose that your current site is down (you can not even login to wp-admin), in this tutorial we will have to do it the difficult manual way.

1.  First is to keep the backups of the original site (example.com) in a safe place and not touch it.  Work with a copy of that backkup instead.  Because we will have to alter this backup.

2.  Create a mysql database on your destination host (example.net).  Remember the database name, database user, and database password that you used in creating this database (try to use the same ones as those found in the wp-config.php of the backed up site if possible).

3.  Find the backed up .sql file of the original host (example.com).  Do a search and replace in the file replacing the domain “http://www.example.com” with “http://www.example.net”.

4.  Import this changed .sql file into the destination host (example.net).

5. Edit the backed up wp-config.php file of the original host (example.com) and update the php defines for DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST to that of the destination database that you had just created.

6.  Upload this wp-config.php to destination host and see if site works.

There could be many reason why it may not work.  One reason in particular is if the wp-config.php has changed due to host differences or if host or install scripts write extra stuff into the wp-config.php.  In which case you might want to use a fresh newly downloaded wp-config.php from wordpress.org to see what differences exist.  Or try setting define(‘WP_DEBUG’, true) in the wp-config.php — perhaps some error messages may help.  Remember to set define(‘WP_DEBUG’, false) when done.