Automated WordPress Theme Deployment from GitHub to Kinsta

I recently began using Kinsta Managed WordPress Hosting after reading good things about them across the web. They utilise the Google Cloud Platform and therefore can handle auto scaling to improve site speeds when traffic surges happen. I am not affiliated with Kinsta in anyway, I am simply finding their hosting solution to be a great one (so far at least).
The Basic Workflow
My local development environment utilises MAMP Pro and Grunt for a nice and smooth workflow. The project is using git and hosted in a private repository on GitHub. Two main branches make up the the repository;
- Master
- Staging
So here you can easily ascertain that i either work off the staging or work from a sub branch that i later merge with staging before deploying to my staging environment. When i’m happy wth the changes, staging is then merged with the master branch.
Kinsta
Kinsta is a managed WordPress, scalable hosting provider. They specialise and only deal with WordPress sites so for this project they are absolutely perfect. I’ve been using them so far for about a week and i’m really happy with their customer services, platform and integrations with things such as Let’s Encrypt free SSL. But most importantly they make staging easy.
Deploy a staging area for development, testing or tweaking and tuning — all in a single click. — Kinsta
Putting it all together
So I have my git repo on GitHub with my two branches; master and staging. I also have my live environment and a staging environment on Kinsta. Now i want to easily commit and push changes to my staging branch and have them automatically deploy to my staging environment.
Easily commit and push changes to my staging branch and have them automatically deploy to my staging environment.
Kinsta gives really is developer friendly; in that you don’t have to hunt around for server details. SFTP, ssh info and ports are all found in one place making it easy to grab these details on the fly, and I love anything that speeds up my workflow. Staging environments are accessible on subdomains like https://staging-site.kinsta.com which also have their own server credentials.
Here comes Deploy
To make life easier, i’m using Deploy which does the git post-receive hook for you. I’m not affiliated to Deploy either but i also highly recommend it, it’s Basic price plan works great for this kind of project and their user interface is extremely easy to set up. Most importantly each project you set up can deploy to multiple servers, in our case; live and development.
Deploy utilises the post-receive hook and therefore once you push your changes and they’re received by GitHub, Deploy can now automatically deploy to your staging or live environments.
Tutorial: Setting it up
1. Setting up staging on Kinsta
First let’s set up our staging environment on Kinsta. I’m going to assume you already have your site setup so go ahead and log in to your Kinsta dashboard. View your sites from the menu on the left side of your dashboard and click “manage”.
Once you’re managing your site, you can create a staging environment from the button to the upper right of your screen:

After creating your staging environment you will now have all your staging environment server details to hand. Go ahead and open a new tab and create your account for free on Deploy.
2. Create your first Deploy Project
So we’ve set up our staging environment, now let’s go ahead and link it to our private GitHub repository by creating a project on Deploy. Go right ahead and click Create a New Project.
Give it a name and from the templates menu, select SSH/SFTP.
Obviously we want to link our project to our GitHub repository so choose GitHub from the “Where is your repository hosted?” option:

Continue and you will be asked to authorise your GitHub account with Deploy. Do this and you a list of your Github repositories will appear.
Now we need to edit the server information in Deploy so that we can deploy our changes to git automatically to our staging environment.
3. Linking Deploy to Kinsta
Go to your projects page from the top menu on your Deploy Dashboard and edit the project we’ve just created by clicking the title of the project.
We’re now going to add a server by clicking the + button to the right, or down on the Add One Now if you haven’t added a server already:

Give your new server a name (you can change this later) and from the protocol options choose SSH/SFTP.
We should still have our Kinsta Staging Environment tab open in your browser at this point, we’ll need the details from this.
On Deploy your hostname is your IPv4 Address on your Kinsta Server Details page. Go ahead and enter the remaining fields with the information we have on Kinsta.
Feel free to Use SSH key rather than password for authentication there is further instructions on Deploy how to do this if you wish. I personally just used the password i have on Kinsta. However the advantage to using SSH key is that if at some point in the future you change your password on Kinsta, you will not have to update Deploy as well.
Your deployment path is given to you on Kinsta as well, but because we’re deploying a WordPress Theme our deployment path must include the WordPress file structure:
www/your_site/public/wp-content/themes/your_theme
Complete the remaining fields if you wish, you’re almost done.
4. Automating post-receive
Finally, we want to enable the post-receive hook so when we push our changes to GitHub, we can then update our staging environment on Kinsta automatically. Here is the Deploy article to help you through this process.
After adding our server to Deploy, we want to Edit Server. This can be done by selecting our project and then clicking the server name we just added, listed on the project page. Once here we want to take our deployment URL:

Copy the URL to the right and turn on automatic deployment if you wish to utilise this feature. *Note that on the free pricing plan, you can only deploy up to 10 times a day. So if like my you like to Commit & Push at the same time then you will quickly run over this limit.
Next log into GitHub and navigate to your repository. We’re going to click the Settings tab and choose Webhooks from the menu to the left.

Copy and paste the deployment URL from Deploy to GitHub and leave all other fields blank or unchanged. You’re now done!
That’s it. Now when you push changes to your GitHub repository, they will be automatically deployed to your live staging environment on Kinsta.
To deploy to your live Kinsta environment, simply add a new server to your Deploy project and repeat the steps above.
