If you have a WordPress site, then you should be backing it up. A popular way to do that is with the UpdraftPlus plugin. Using the free version, you can set up a regular backup of all important files (including database), to a remote server. There are various options, but the one I use is to have it backup to my free Dropbox account.
So far, so good. However, I realized that if something ever happened to my live site (if it stopped working or got corrupted or whatever), then I’d better know how to restore it from the Updraft backup. Updraft sells an add-on called Migrator that apparently helps you do this, but I decided to save my money and learn how to restore my site manually.
Below are the steps I used to do this. It’s not hard, but you need to know how to log in to the control panel (usually called cPanel), of your web host. You then need to use the File Manager and phpMyAdmin app there. Last, you’ll need to edit the wp-config.php file.
Note: I’ve done the following a few times and it’s worked for me. Please leave a comment if you think there’s something I left out, etc.
Step 1: Download a Copy of Your Backup
Download a copy of the files that Updraft sent to your cloud backup service (or wherever you set it up to back up to).
* If the reason you’re doing this is because your site is having problems and you want to restore it, then make sure to grab a backup from before the problem occurred; otherwise, you may end up ‘restoring’ the same corrupt site you’re trying to fix.
The files should look something like this:
backup_[date]_[site_name]_[random_code]-db.gz (database backup)
backup_[date]_[site_name]_[random_code]-others.zip (index.php, etc.) backup_[date]_[site_name]_[random_code]-plugins.zip (plugins folder) backup_[date]_[site_name]_[random_code]-themes.zip (themes folder)
backup_[date]_[site_name]_[random_code]-uploads.zip (uploads folder)
Step 2: Install WordPress on Target Server
Install a fresh copy of WordPress on the target server (that is, wherever you want to restore your site to). The easiest way to do this is with the WordPress installer inside the Softaculous suite of installers in your cPanel. (The software installers are usually toward the bottom of the cPanel window.)
• to be safe, you’ll probably want to install the same version of WordPress that your site was running on. (However, my original site was on WordPress 5.1.1 and I migrated it to a 5.2.2 install and it seems to work fine.)
• I change the default install location from “wp” to something else, just to make it a bit harder for hackers. Or, delete the “wp” if you want to install in your site’s root folder.
• in the ‘Advanced’ section of the installer, make a note of the Database Name and Table Prefix
• don’t bother changing anything else in the installer window, as you’ll be overwriting it with your backup files later
• click Install
• when finished, copy the URL of the new install
Step 3: Upload and Extract Your Files
Use File Manager in cPanel to navigate to the “wp-content” folder inside the new WP install.
• delete all it’s contents
• upload your Updraft backup files (all the .zip files; don’t upload the ‘db.gz’ database file here)
• Extract the files once uploaded
• delete the .zip files
Step 4: Upload Database, Replace URLs
• Open phpMyAdmin in cPanel
• find the new database that belongs to the WordPress install
• click on the new database on the left
• click ‘Check all’ on the right to select all tables in the db
• from the popup menu, choose ‘Drop’ (means same as ‘Delete’)
• click Yes in next window to confirm
• click Import
• click Choose File and browse to the ‘db.gz’ database backup file in your Updraft backup folder
• click Go
• wait for db to be imported (can take a few minutes)
• after import finishes, click ‘wp_options’ line in database
• click Edit on the first line. Replace the old URL there with the new URL of the new WP install
• do the same with line 2 (replace old URL with new one)
• make a note of the ‘table prefix’ in your database at this point, YOU WILL NEED THIS LATER. For example, in my database, the ‘options’ line has “wp_” before it. This is my ‘table prefix.’ (Other databases may have a couple letters after the “wp”, for example: “wpys_”. (The table prefix includes the underscore (_).)
• close the phpMy Admin window
Step 5: Edit wp-config.php file
• in File Manager, navigate to the directory (folder) of your new WP install
• single-click to select the ‘wp-config.php’ file
• click Edit (or, right-click > Edit)
• find the line that says
$table_prefix = ‘wp**_’;
• change it to the table prefix of your database as you noted in Step 4, above. (Make sure not to delete the single quote (‘) characters around the prefix.)
• click Save Changes. After saved, close the window.