{"id":3335,"date":"2021-07-26T15:18:00","date_gmt":"2021-07-26T20:18:00","guid":{"rendered":"https:\/\/n8finch2024.local\/?p=3335"},"modified":"2024-02-26T21:54:22","modified_gmt":"2024-02-27T03:54:22","slug":"an-ideal-wordpress-development-and-deployment-workflow-using-wp-migrate-db-pro-and-deployhq-or-buddy","status":"publish","type":"post","link":"https:\/\/n8finch2024.local\/an-ideal-wordpress-development-and-deployment-workflow-using-wp-migrate-db-pro-and-deployhq-or-buddy\/","title":{"rendered":"An Ideal WordPress Development and Deployment Workflow using WP Migrate DB Pro and DeployHQ or Buddy"},"content":{"rendered":"\n
This post originally appeared on the Strattic.com<\/a><\/strong> blog on April 21, 2021<\/em>.<\/p>\n\n\n\n WordPress has a reputation for being an old-school piece of software, but while it runs on what is perceived as a legacy server stack, it can most definitely be used in conjunction with modern web development workflows. Many developers around the globe are busy building large-scale, sophisticated WordPress projects, and utilize such techniques as CI\/CD and version control (gasp!) while doing so.<\/p>\n\n\n\n At Strattic, many of our customers are like the ones I described above, and that\u2019s why we often get asked about how to set up development and deployment workflows with WordPress in general, and with static WordPress specifically. There are many ways to do this, and many great solutions out there that try to make CI\/CD with WordPress a breeze.<\/p>\n\n\n\n While our mission at Strattic is to make WordPress sites faster, more scalable, and completely secure, we also aim to help teams of developers and stakeholders be efficient and effective in managing and growing their sites. This post aims to do just that: help you build and utilize a workflow that allows you to both keep your code under version control, while not worrying about overwriting your production database.<\/p>\n\n\n\n We\u2019ve all been there, and it\u2019s no fun.<\/p>\n\n\n\n This guide assumes that you have a working knowledge of setting up a local development environment, a production site (hopefully on Strattic!), knowledge of Git and version control, and you need to manage multiple environments and components without losing your mind.<\/p>\n\n\n\n Don\u2019t worry! We\u2019re here to help! 🤓<\/p>\n\n\n\n In this guide, I will also be making use of a premium plugin called WP Migrate DB Pro<\/a> with its Media Files addon, which handles database and media files migration, as well as serialized search and replace, migration profile creation, and one-click migrations. I\u2019ve used it on (I\u2019m not exaggerating) hundreds of sites over the last half-decade and can only sing its praises. There are other migration tools available, but this one takes the cake! (And you know we love cake<\/a> at Strattic)<\/p>\n\n\n\n Before we get started, there\u2019s some common ground we need to establish.<\/p>\n\n\n\n In this article, I\u2019ll be referring to the WordPress site hosted on Strattic as your \u201cProduction environment\u201d and, assuming you are developing on your laptop or desktop machine, your local development environment as \u201cLocal environment\u201d (or just Production and Local, respectively). Please note, on Strattic, there is also a \u201cLive\u201d static site, and a \u201cPreview\u201d static site, which are created or updated when you publish your Production WordPress site.<\/p>\n\n\n\n There are numerous ways you could set up your workflow, and you might also have a \u201cdevelopment\u201d environment where your development team tests new features, or a \u201cstaging\u201d environment, where your QA team might go through automated and manual testing. The combinations and possibilities are endless, and I\u2019m limiting environments to Production and Local for ease of explanation.<\/p>\n\n\n\n It is also important to think of your WordPress project as three separate pieces:<\/p>\n\n\n\n Each of these is distinct in how they should be understood, organized, and managed. Since we\u2019ll be dealing with multiple environments, knowing where your \u201csource of truth\u201d for each of these components is very important. We\u2019ll look at them in the next section.<\/p>\n\n\n\n It\u2019s important to know the difference between \u201csyncing\u201d and \u201cmigrating\u201d sites.<\/p>\n\n\n\n Always make sure you have a recent backup of at least your Production environment before you attempt to set up a deployment workflow. At Strattic, daily backups are automated, and if you want to trigger a backup, you can do so in your dashboard.<\/p>\n\n\n\n Ok, with these important considerations discussed, let\u2019s look at an overview of the deployment workflow.<\/p>\n\n\n\n As you might guess, the workflow laid out here is specific to WordPress. The process might differ from other websites or web apps you\u2019ve worked on before.<\/p>\n\n\n\n The workflow can be summed up in this sentence:<\/p>\n\n\n\n \u201cCode goes up, Database and Media Files go down\u201d.<\/strong><\/em><\/p>\n\n\n\n What does this mean in practice?<\/p>\n\n\n\n First, code moves from a Local environment to a Production environment, i.e. up \u2191. \u201cCode\u201d is everything you want to version control, typically files ending in a .php, .js, .css, or .html extension (and sure, if you\u2019re doing JSX or React stuff, or Vue stuff, you\u2019re going to version control .jsx, .vue, .whatever files).<\/p>\n\n\n\n The source of truth for the codebase should always be the default, main, or master branch of your Git repository.<\/p>\n\n\n\n Next, database and media files move from the Production environment to the Local environment, i.e. down \u2193. Just about everything that is managed in the WordPress admin area (posts, pages, plugin and theme settings) gets saved in the database.Your database should not contain any executable code (though this sometimes occurs when plugins store code in the database). Essentially, if you\u2019re using wp-admin to make and save a change, it\u2019s probably getting saved in the database.<\/p>\n\n\n\n The source of truth for the database of a site should always be the Production database.<\/p>\n\n\n\n Media files (or \u201cuploads\u201d) are typically uploaded through the wp-admin. Some transformations on the images are done based on database settings at that time. The images are not stored in the database, but are stored in a file system. These media files and other uploads are not code, so they don\u2019t need version control. However, you do need to be aware of them, as during a migration and while replacing URL strings, if you don\u2019t move your images from one site to another, image files will break, and other files in the uploads folder (e.g. caching scripts) will break your site.<\/p>\n\n\n\n The source of truth for the media files or uploads of a site should always be the Production database and media files.<\/p>\n\n\n\n This is the workflow we\u2019ll be covering below. The basis for this workflow, I believe, was started by Pantheon here<\/a>.<\/p>\n\n\n\n However, on Strattic, the workflow and concepts are a little different, since your Live static site is a static replica of your WordPress site, and there is no \u201cdatabase\u201d in a typical WordPress sense.<\/p>\n\n\n\n Ready? Ok, let\u2019s begin.<\/p>\n\n\n\n If you\u2019ve got your Production site running on Strattic, this is the easy part! 😎 Most quality WordPress hosts today, like Strattic, will run daily backups that you can both trigger and access to download. If your current host does not offer this service, consider checking us out!<\/p>\n\n\n\n
\n\n\n\n
\n\n\n\nOverview and understanding<\/h2>\n\n\n\n
\n
Syncing vs migration<\/h2>\n\n\n\n
\n
Backups. Ho hum. But seriously.<\/h2>\n\n\n\n
The ideal workflow for working with WordPress:<\/h2>\n\n\n\n
Step 1: Backup and download your Production site from your host<\/h2>\n\n\n\n