WordPress Deployment Part 4: Automated Deployments
In my last article, we looked at different methods of deploying a WordPress site using Git. We also looked at using an external CI service (such as Travis) to automatically trigger a deployment on your remote git repo.
In this article, we’re going to build on what we have looked at previously and consider some alternative hosted services that can help us with automated deployments for our WordPress site. There are many hosted services that we could use to deploy our WordPress site but we’re just going to look at a few of the bigger ones: Buddy and DeployBot. Unlike Travis, these services are dedicated to automated deployments and offer a lot more functionality and flexibility.
As I’ve mentioned several times now, for the purpose of this series I’m going to assume you have your site stored in Git and you are using Composer to manage your WordPress site, plugins and themes. If you’re looking for a quick code example to get you going you can use this skeleton repo I’ve set up (that I’ll also be using for demo purposes in this article).
As was the case in my previous articles, I’m also going to assume you have a destination server ready for your deployment. All of these examples will require SSH access to this server.
Deploying WordPress using Buddy
Buddy is a relatively new player in the automated deployments space but has quickly become popular due to its support for a huge array of different technologies and a great UI. So let’s see how we can deploy WordPress using Buddy.
First, if you haven’t done so already, sign up for a Buddy account and create a new Workspace. When you’re ready, create a new project in Buddy and select your Git repository. In our case, we’re going to select my skeleton repo which is hosted on GitHub.
Next, we’re going to add a new pipeline. You can create pipelines for multiple environments if you wish (e.g. staging, production etc.) but we’re only going to need one for the moment so just call it “Production”. We also want to trigger this pipeline whenever we push code to our
master branch, so select “On Push” as the trigger mode and “master” as the branch.
Next, we need to add some actions to our pipeline so we can build and deploy our WordPress site. In our case we need to do two things: run
composer install and then deploy the files to our server. So first let’s add a new PHP action so we can run
For the run commands simply enter
composer install. Buddy uses Docker containers to run all of its actions in. So in the environment configuration, we’re going to select Docker Hub Public and use the official PHP 7.2 Docker image to run our commands (I’m using PHP 7.2 but you should use whatever version of PHP is being used on your destination server).
Next, we’re going to add an action to copy our files to our server via SSH. We’re going to do this by adding a new SFTP action.
Make sure you select the “Pipeline Filesystem”. This makes sure that we transfer any files that have been generated in the pipeline (i.e. in our PHP action by running
composer install) as well as our files from the Git repo itself. In the “Where to Upload” section enter the destination server details and configure the remote path to be the location you want to deploy your WordPress site too.
Now that our actions are set up, we just have one more thing to take care of. It’s best practice to make sure we don’t store sensitive information in our Git repo (e.g.
wp-config.php details). In my skeleton repo I have it set up to read these details from a
local-config.php file (or a
production-config.php file depending on the environment). We need to make sure we deploy this file too, even though it’s not stored in our Git repo. Thankfully Buddy has a handy feature where we can manually add config files to the pipeline filesystem by simply uploading them via the “Filesystem” tab. So let’s go ahead and upload a
production-config.php file, making sure to fill in the correct details for your server and database (if you don’t want to store these credentials in Buddy you can always upload this file to the server manually).
Ok, now we’re ready to run the pipeline! Go ahead and hit “Run pipeline”. Buddy will display a nice progress page where you can see the logs of the actions that have been run.
That’s it! Our WordPress site has been deployed to our server. Every time you push changes to the master branch of your Git repo Buddy will detect the “push” event and re-run the pipeline.
Deploying WordPress using DeployBot
DeployBot is a similar app to Buddy but has been on the scene a lot longer. It was built (though it was sold late last year to another company) by the talented folks at Wildbit who build other great products you might have heard of like Postmark, Beanstalk, and their work in progress Conveyor. So let’s see how we can deploy WordPress using DeployBot.
First, if you haven’t done so already, sign up for a DeployBot account. Straight away DeployBot will ask you to connect an account and select Git repository. In our case, we’re going to select my skeleton repo which is hosted on GitHub.
Next, we’re going to create an environment. Again we only need a single environment so let’s call it “Production”. Despite the warning, we want to deploy our code on every push so select the “Automatic” deployment mode and make sure the
master branch is selected.
As before, we’re going to need to run
composer install and then deploy the files to our server using SFTP. So select the SFTP option and fill in the server connection details. Under “Compile, compress, or minimize your code” add our
composer install command. Leave the other setting as-is for the moment.
As before we’re going to need to add our
production-config.php file to be deployed with the rest of the files. DeployBot has a “Configuration Files” tab where you can add any config files you want. So go ahead and add a
production-config.php file now.
Now we should be ready to deploy our site! Head back to the “Overview” tab and hit “Deploy” next to your Production environment. DeployBot will display a progress page where you can see a log of the entire deployment.
That’s it! Our WordPress site has been deployed to our server. Every time you push changes to the master branch of your Git repo DeployBot will detect the “push” event and re-run the pipeline.
As you can see, using hosted services such as Buddy or DeployBot can make setting up automated deployments for your WordPress site very simple. And we’ve really only just scratched the surface of what these apps are capable of! I recommend having a good look around all of the functionality both of these apps can provide. We use Buddy at Delicious Brains to deploy several apps and sites, including deliciousbrains.com itself.
Speaking of automated Git deployments, SpinupWP makes hosting WordPress yourself super simple and includes an automated Git push-to-deploy feature.
In my next article, we’re going to look at a specific deployment process called “atomic deployments” to see how we can improve our deployment workflow and reduce downtime during a deployment.
Have you ever set up automated deployments for a WordPress site? If so how did you do it? Got any good tips of deployment automation? Let us know in the comments.