Remember your amateur days of cowboy coding in WordPress? Tedious scenarios of editing website files directly from FTP. Every press of the refresh button could risk your website magically disappearing. Those days are over. There’s a lot of great tools that keep you in full power of your website, ensuring local files and data is up to date.
Synchronizing files and databases across environments is not easy to wrap your head around at first. There’s many different moving parts and steps involved, that once understood, makes the whole process seem simple.
Keeping Local Updated Is Not Only Necessary But Imperative
Here’s an example. John has been building a website about cats for 5 weeks now. John has just placed the website on a development server where the clients can view the progress of the site. Once the clients give him a document of changes, John kicks into full gear. He makes the revisions on his local machine making sure everything requested is complete. He then uploads the entire site to the development server, overwriting the old development version.
Now this process works in some cases, but it’s time consuming and inefficient. Imagine the client has a few sentences to change, and John has to upload the entire site again. Or what if the client has been upload content to the website, such as blog posts or cat descriptions. John can’t upload his version or he’ll override their changes.
Although there’s a lot of tools out there for this workflow, there’s one that I’ve found particularly useful:
Migrate DB Pro – A premium plugin used to push and pull databases from servers. This is the golden piece of the puzzle. There’s alternatives like WP-CLI, but most of the article is specific to this plugin.
So let’s get started.
At this point your website should be in two places, your machine and the development server the client is viewing. Once you make the website revisions locally you will want to setup a Git remote to allow you to update the files. In my workflow I use WP Engine and make use of their Git Push feature. If you need help doing this with WP Engine specifically here is an article on what’s involved: Using Git With WP Engine: Outlining The Process.
This seems like a tedious process but is amazing in the long run. No more connecting to the FTP server and uploading the files over a period of 5~20 minutes. Enter four simple words in Terminal and watch it go to work.
git push name_of_remote name_of_branch
name_of_remote is generally “origin” or “production”, while name_of_branch is generally “master” or “staging”.
If you’re not using version control, that’s okay. You will update the files the old fashioned way through FTP.
Install WP Migrate DB Pro, and WP Migrate DB Pro Media Files on both the local and development website. Activate the license keys and update the plugins to their latest versions. You will use these plugins when you need to either:
1) Pull – Update the local website with content that has changed on the development website. This it typical when the client or someone else in your company is adding content. You would want to pull this down before you start working locally so that way you push later, you’re not overwriting anything.
2) Push – Update the development site with content that has changed on the local website. This is typical when you have been updating everything yourself on your machine.
Always think before you push or pull! Has anything been changed that you could overwrite? Sometimes you have to be proactive about who’s doing what or you risk stepping on each others toes.
Login to both WordPress sites, enable permissions in the settings of the WP Migrate DB Pro plugin dependent on whether you’re pushing or pulling. Input the connection data and sync your databases.
Here’s a recap:
- Make the changes on your local version of the site.
- Commit the changes in your git repository.
- Push the files up to the development server.
- Push the database up.
I hope this wasn’t too confusing. The hardest part is determining what’s best for your current scenario/project. Good luck!