Overview
Some time ago I started using web hosting from Cloudways and I am very happy with it (before that by the way I had Bluehost and I don't recommend it to anyone). At the same time I also wondered how to automate the uploading of new versions of sites. I used to simply upload files via sftp, but nowadays it is modern and also full of possible errors because of human factor.
So I started looking for other options. I use GitHub for development and Cloudways for hosting as it became clear. So a few options for implementing the deployment came up right away:
- Leave everything as it is and pour all changes manually via sftp 🙂
- Use the Deployment via GIT feature built into Cloudways.
- Use GitHub Actions which I had some experience with before.
The first option falls off, because I have already used it and it was time to move to something more automated due to frequent updates and a large number of sites. But the next two can be considered in more detail.
Default Cloudways deploy system
Cloudways already has a built-in deploy system for Git. It's not perfect, but I think it might work for a lot of people.
How it is working
The solution offered by Cloudways cannot be called a complete CI/CD. All you have to do is add your Git repository address and then you can click Start Deployment in the Cloudways admin panel to upload all the files from the master branch of your repository to the server.
The main inconvenience here is that every time you need to add some changes to the site you have to go to the admin panel and press the deploy button. Not very convenient in times when everything can be automated and all changes can be automatically uploaded to the server when adding to Git.
How to set it
It's pretty easy to set up in a few steps:
1. Make sure in advance that you already have an Application created. If you don't already, now is the time to create it.
2. Go to your Application page and open Deployment Via Git tab.

3. Click the View SSH Key button. Copy the code that will appear. They go to your Git vendor and add this SSH key into it. For example, if you are using GitHub then open your profile settings -> SSH and GPG keys page, click the New SSH key button and paste previously copied SSH key.

4. Set your git address inside the Git Remote Address field. For example, if you are using GitHub the address can looks like git@github.com:ILLID/My-Cool-Repo.git
.
5. Additionally, set Branch and Deployment path options.
6. If you were doing everything correctly then just click Start Deployment button. The content of you repository must be deployed to the selected folder.
Conclusion
Advantages: easy setup.
Disadvantages: need to perform additional actions for each deployment, a limited number of settings.
What is Github Actions?
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline.
In other words, it's a thing that can make your life better by automating standard tasks like building, running tests, and deploying. In our case, we're only interested in the last point, although GitHub Actions allows you to do much more.
As the name itself makes clear - Github Actions is only available to Github users. Other Git vendors, such as Bitbucket or GitLab, have their own similar pipelines. But in our case, it is Github that we are considering.
How it works
Within your repository, you create a special yml
file which should be located in the .github -> workflows
folder. Inside this yml
file you describe the entire CI/CD pipeline for a particular repository.
It describes the event which must happen to start the workflow, e.g. a push of code into the master branch. It also describes the actions that must happen after that, one after another. For example - start the build, then start tests, then start uploading to the server. If one of the steps fails, then the whole process stops.
In this article, we will not describe the syntax and all the features of GitHub Actions. In our case, we are interested only in the specific task of Deploying code from the GitHub repository to the Cloudways server. If you want to learn more about GitHub Actions and all its features, the official documentation is the best place to do it.
We've described what GitHub Actions is in general detail. Below are specific instructions on how to use GitHub Actions to deploy to our Cloudways server.
Github Actions for Cloudways
So we have an Application configured on Cloudways and we have a repository on GitHub from which we want to upload code to our server.
What we want: the code from our repository in the master branch should be automatically uploaded to the server every time we push to the appropriate branch.
The following is a step-by-step breakdown of what you need to do to do this:
1. Inside your GitHub repository, create a folder called .github/workflows
. Next, create a deploy.yml
file inside that folder.
2. Add following content inside deploy.yml
file:
name: deploy
on:
push:
branches:
- master
jobs:
new-version-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Build dist folder
run: |
mkdir -p dist
rsync -r --exclude 'dist' --exclude '.git' --exclude '.github' --exclude '.gitignore' . dist
- name: Deploy with rsync
env:
remote_host: ${{ secrets.CLOUDWAYS_HOST }}
remote_port: "22"
remote_user: ${{ secrets.CLOUDWAYS_USER }}
remote_key: ${{ secrets.CLOUDWAYS_SSH_PRIVATE_KEY }}
local_dir: "dist/"
remote_dir: ${{ secrets.CLOUDWAYS_PATH }}
run: |
mkdir ~/.ssh
echo "$remote_key" > ~/.ssh/gh_actions_key
chmod 600 ~/.ssh/gh_actions_key
rsync -avzr -e "ssh -p ${remote_port} -i ~/.ssh/gh_actions_key -o StrictHostKeyChecking=no" ${local_dir} ${remote_user}@${remote_host}:${remote_dir}
We won't pay much attention to what exactly is going on here. As mentioned above, you can explore the official GitHub Actions documentation to learn more.
In short, we set a condition for starting steps from a file - a push to the master branch. If this happens, we create a local dist
folder where we move all files from the master branch, then connect the Cloudways server and move all the contents of dist
folder to this server in the folder which is specified in the remote_dir
parameter.
Remember to push these changes to your repository.
3. Next, we need to generate SSH keys. You can read this Google documentation to learn more about how to do that. As a result I must have you key files - public and private.
4. Open your Cloudways server page -> Master Credentials tab and click SSH Public Keys button. Inside the pop-up click Add button and paste the SSH public key that you generated on the previous step.

5. Next you need to add several secrets for your GitHub repository that you want to deploy from. Secrets are some repository-specific values that contain sensitive data like password, user names, SSH keys, etc.
So open your GitHub repository -> Settings -> Secrets -> Actions page. Here you need to add several secrets that we need for proper work of our deploy.yml
file.
CLOUDWAYS_HOST
- Open your Cloudways server page -> Master Credentials tab and copy the value for Public IP option.
CLOUDWAYS_USER
- Open your Cloudways server page -> Master Credentials tab and copy the value for Username option.
CLOUDWAYS_SSH_PRIVATE_KEY
- SSH private key that you generated previously.
CLOUDWAYS_PATH
- The value for this secret must look like that:
applications/{APPLICATION_FOLDER}/public_html/
where {APPLICATION_FOLDER}
- value from your Application -> Application Settings -> Folder option.
With such path repository files will be uploaded to the root folder of your application. You can change this and specify a more specific path. For example, if your repository contains only theme files then you probably need to upload it to the WordPress themes folder. In this case path can looks like that:
applications/{APPLICATION_FOLDER}/public_html/wp-content/themes/
6. Additionally open Cloudways Application -> Application settings page and reset folder permissions with the appropriate option.
7. We are done. Now just make any changes inside your repository master branch and push the changes. All such changes must appear on your server within several minutes.
Don't forget that Cloudways includes some caching by default, so probably you will need to clear it in order to view the changes.
So just open your WordPress admin dashboard -> Settings -> Breeze -> Varnish and click the Purge button.
