How to Deploy Private GitHub Repositories to cPanel With GitHub Actions [Continuous Deployment (CD)]

Ridbay
4 min readMay 1, 2021

--

How to Deploy Private GitHub Repositories to cPanel With GitHub Actions [Continuous Deployment (CD)]

This article shows you the step by step on how to automatically deploy a private GitHub repository to cPanel on every push.

If you are interested on how to deploy a public repository, CLICK HERE

Let’s go straight to the point;

You are working on a project in a private GitHub environment, You would want to deploy your codes to cPanel so that it can go live.
The workflow is as follows;

  1. Make some changes on your local machine
  2. Make the changes in a separate git branch,
  3. Once you are done with the testing and everything seems perfect, you would want to merge to a master branch (With the assumption that the master branch is your production branch, anything you push to the master branch is ready to go live)
  4. You push to the remote master branch and it automatically deploys to your cPanel (Live environment for your users to see).
  5. Repeat steps 1–4

To achieve this, you would need;

  1. An FTP/SFTP account created in your cPanel account
  2. A project under Git version control and hosted on GitHub
  3. A GitHub Action Workflow Configuration.

Let’s get started

This is not a “One size fits all”, there are a lot of methods to deploy a private GitHub repo to cPanel, I found this as the easiest.

THE STEPS

  1. Log in to your cPanel account and create an FTP account
Create FTP in cPanel
Add FTP account

2. Keep your ftp account username and password as you will need them later.

3. Next you need to know your server IP address (or Hostname but the IP address works fine for me), You can reach out to your host service provider if you do not know your IP address.

4. Go to your private repository on GitHub, click on SETTINGS, then click on SECRETS to add your FTP account username, password and server IP

create SECRETS in GitHub

5. On the SECRETS tab, click the NEW REPOSITORY SECRET BUTTON on the right hand side, to add a new secret

create new GitHub secret

6. Add the details as follows (Using your own details)

The names should be FTP_SERVER, FTP_USERNAME,FTP_PASSWORD

and the values should be your own secret details respectively and click the ADD SECRET BUTTON

Here is an example;

Add New Secret on GitHub

7. The next step is to create a GitHub action workflow; The GitHub actions take place on the GitHub server.

In your GitHub repo, click on ACTIONS

GitHub Actions

8. Click NEW WORKFLOW, You can choose a workflow template but for the sake of this tutorial, we will be creating our own workflow.

Click on any template (I selected the first template), then edit the configuration (“yaml” configuration file)

Choose a workflow action template

9. Change the file name to your own choice. (I changed mine to deployTocPanel.yml), make sure it has the .yml file extension

create a deployment file on GitHub

Place the below configuration code in the file

a. For Nodejs Applications, use this;

b. For other applications or just file uploads (php etc), use this;

Make sure you change the branch where you want your codes to be deployed from, in my case I am deploying from master branch

10. Once you are done, click on START COMMIT button on the right hand side

Save GitHub Workflow

This will automatically create a /.github/workflows/directory and places the configuration file in it.

11. Anytime you push your codes to the master branch, it automatically deploys to cPanel via your FTP account.

12. Anytime you push to your master branch, you will see something similar to what’s below

GitHub action in progress

The Amber color means that deployment is in progress.

GitHub action in progress

Once the deployment is successful, the color changes to GREEN, This means your code has been deployed successfully to cPanel.

GitHub action successfully deployed

If it fails, it will change to RED

GitHub action failed

I hope this article helps you to set up a continuous delivery for your project.

You can leave a comment below to let me know how helpful it is.

SHARES!!!

--

--

Ridbay
Ridbay

Responses (14)