Recently, I’ve been fine-tuning my WordPress migration process to minimize the margin of error during an upgrade. One tool that has helped me standardize each upgrade is a simple checklist. This checklist details the essential steps in upgrading from a local development environment to a live website. The list can also be used when migrating a WordPress site to a new server or domain.
Setup a Maintenance Holding Page
Creating a maintenance holding page is an essential step in maintaining security and professionalism when updating a site. It can seem difficult to create a page that blocks users from your site while allowing you to access it during the upgrade. Guess what? There’s a way to do that and it is pretty easy.
Using .htaccess we can set up permissions for specific IP addresses including the one for your computer. Then we can tell the file to route all other traffic to the maintenance holding page. In the example below, I have put the maintenance page and the files associated with it in their own directory. You may need to change the paths to match your file structure.
Add the code below to the top of your .htaccess file and substitute your public IP address for the one in the example. You will also need to change the paths below to match your file structure.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^127.0.0.1$
RewriteCond %{REQUEST_URI} !/maintenance/index.htm$
RewriteCond %{REQUEST_URI} !.(jpg|jpeg|png|gif|css|ico)$
RewriteRule .* /comingsoon/index.htm [R=302,L]
Note: To turn the maintenance page off, simply place a # at the beginning of each line in this section.
That should do it. I recommend you check that this setup is working correctly on a test site before using it on a live website. Once you have a working version of this file, you can reuse it every time you perform an upgrade. Pretty cool, huh?
Export the Local Database
The next step is to export our local WordPress database. We will be replacing the production database with this copy later in the checklist and it is best to export it before we turn on the maintenance page. This way we minimize the amount of time our site is offline.
Export a Copy of the Production Database
Just as we exported a copy of the local database, it is good practice to export a copy of the production database. This can be helpful if something goes wrong during or after the upgrade. It can be especially useful if you make a mistake when switching the permalinks from local to production file paths. I recommend storing this copy until the next time you make an upgrade as it can be beneficial to have something to fall back to when problems surface.
Turn On Maintenance Holding Page
Okay, now we’re ready to get started. Turn on the maintenance page by removing the # from the beginning of each line in the section we added above (.htaccess file). Navigate to your site and ensure that the maintenance page is working correctly. You should be able to visit the site from the IP address you used in the* .htaccess* file, but reverted to the maintenance page when visiting from any other device. An easy way to test this is by visiting the site from your mobile device or another computer.
Depending on the type of site you maintain, you may want to send out an email 24-48 hours before you plan to make the updates. It would really suck if one of your users was almost done with a checkout process and got redirected to the maintenance page before they could finish.
Upload the Local Files to the Production Server
Now that we’ve hidden our site from the public view, it’s time to upload our changes. Using your favorite FTP client (FileZilla is always a good choice), upload all of the files in your local WordPress directory to the live site. This may take a while since the WordPress directory can contain a few thousand files depending on the plugins and themes you have installed.
Replace Production Database with Local Copy
Remember that copy we made of the local database? It’s time to remove the tables from the live database and import the copy of our local database. Remember we exported a working copy of the live database, so if anything goes wrong we can revert to that copy and try again.
Use Search Replace DB to Correct File Paths
One of the most challenging tasks in migrating a website, whether that is local to production or from one domain to another, is changing the permalinks. Changing the WordPress Address and Site Address settings from the WordPress Admin Panel is not enough. Your page links may work, but the links to images and other files created by WordPress will not be correct. To avoid this mishap, I use a helpful script called Search Replace DB. By following the instructions in the script you can search for any string in a database and replace it with a new value.
Note: Delete the searchreplacebd2.php file from your WordPress directory before going live. Otherwise anyone will be able to access the script and change values in your database. You don’t want that…it would be a very dark day.
Update Database Details in wp-config.php File
If you were to visit your website now you would see the infamous Error Establishing a Database Connection message. This is because we have yet to change our database details in the wp-config.php file. Crack open that file and change the database details to the correct values for your production database. Reload your website to ensure that the connection is being made and no other errors are present.
Double Check Everything
Almost done! The final thing to do before releasing this marvelous update to the world is to check it for bugs. Hopefully, you have checked your work thoroughly before deciding to upload it, but bugs have a way of popping up even with extensive testing. This is also a great time to visit each page of your site to ensure that images are loading and layouts are displaying correctly.
Lastly, log in to the WordPress Admin Panel and check that your WordPress Address and Site Address settings are correct.
Turn Off Maintenance Holding Page
Once you are satisfied that everything is working properly, revisit the .htaccess file and comment out the lines that create the maintenance redirect by using a # at the beginning of each line.
Final Thoughts
This checklist should help you standardize your WordPress upgrades and minimize issues. Feel free to adapt it to your specific project and add steps where they are needed. If an error does arise, track it back to one of the steps and make a plan for avoiding that error in the future. Here is the list again for quick reference:
- Setup a Maintenance Holding Page
- Export the Local Database
- Export a Copy of the Production Database
- Turn On Maintenance Holding Page
- Upload the Local Files to the Production Server
- Replace Production Database with Local Copy
- Use Search Replace DB to Correct File Paths
- Update Database Details in wp-config.php File
- Double Check Everything
- Turn Off Maintenance Holding Page