DEV Community

Cover image for How to Automatically deploy from GitHub (Git) to cPanel
Emmanuel Uchenna
Emmanuel Uchenna

Posted on • Edited on

How to Automatically deploy from GitHub (Git) to cPanel

How to Automatically deploy from GitHub (Git) to cPanel

This tutorial provides a quick way of deploying files from GitHub to cPanel. We are only deploying from Git(Hub); thus making GitHub our single source of truth. In other words, we will be pulling from GitHub.

cPanel is an online Linux-based graphical user interface (GUI) used as a control panel to simplify website and server management. cPanel allows you to publish websites, manage domains, organize web files, create email accounts, and even more. cPanel is one of the popular control panels.

In this tutorial, I shall walk you through configuring and setting up your Git repo and have it auto deploy to cPanel. Let's get started. First, you need to login into cPanel.

Login in into cPanel

To login to cPanel, on your browser, navigate to https://yoursite.com/cpanel or https://yoursite.com:2083.

1. Navigate to Git Version Control

To navigate to Git Version Control, follow cPanel > Home > File > Git Version Control. The GVC allows you to configure deployment for your cPanel-managed repositories.

Navigate to Git Version Control

2. See or Link your Repositories

The next screen that you will see will enable you manage your repositories. I have a repository already linked from GitHub to cPanel. If you currently do not have any repo linked, then go ahead and click on "Create" .

If you already have a repo from Git link to your cPanel, please skip to Step 4

See or Link your Repositories

3. Clone your Repository

This step will enable you to clone your remote repo to cPanel. You should fill in the fields such as clone URL, Repository Path.

  1. The Clone URL refers to your remote repository URL. It must begin with either http://, https://, ssh:// or git:// Example: https://github.com/Eunit99/eunit99.git

  2. The Repository Path refers to directory where your repo will live on cPanel. The path is usually home/YOUR-USERNAME/REPOSITORY-NAME
    If everything looks good, go ahead and click on "Create"

Clone your Repository

4. Manage Repositories

This step will allow us manage our repositories which we have on cPanel. To navigate to Git Version Control, follow cPanel > Home > File > Git Version Control. The GVC allows you to configure deployment for your cPanel-managed repositories.

You will see a list of all repositories currently linked to cPanel from Git. Click on Manage to be taken to the next step.

Manage Repositories

5. Pull or Deploy

After having filled the fields for information about your repos in step 4 above, now is the time to clone your remote repo to cPanel just like how you would on your local machine ๐Ÿ˜Š

Pull deployment pulls changes from a remote repository to your cPanel and deploys your new changes live.

  1. Click on Pull or Deploy tab
  2. Click on Update from Remote
  3. Click on Deploy HEAD Commit

Pull or Deploy

๐ŸŽ†โœจCongratulations! You have successfully deployed a remote repo to cPanel

๐Ÿ˜ฒ But we wanted an auto deployment of new changes from GitHub to cPanel, isn't it? If yes, then keep reading.

6. Setting up auto-deployment

In order to deploy changes from a cPanel-managed repository, you must have a .cpanel.yml file in your top-level directory of your repository. Create a .cpanel.yml file and add this code below:

Setting up auto-deployment


 YML
##### THIS ALLOWS US TO DEPLOY THE SITE FROM A GIT REPO ######
---
deployment:
  tasks:
    - export DEPLOYPATH=/home/your-username/public_html/
    - /bin/cp -R .vscode $DEPLOYPATH
    - /bin/cp -R assets $DEPLOYPATH
    - /bin/cp -R css $DEPLOYPATH
    - /bin/cp -R fonts $DEPLOYPATH
    - /bin/cp -R img $DEPLOYPATH
    - /bin/cp -R js $DEPLOYPATH
    /bin/cp index.html $DEPLOYPATH



Enter fullscreen mode Exit fullscreen mode
  • Replace your-username with your actual cPanel username
  • Save and push to your remote repo and repeat step 5.
  • NOTE: My code above tells cPanel the folders and files to automatically pull. Your repo file structure might differ.

Further reading

  1. Guide to Gitโ„ข - How to Set Up Deployment

This tutorial has been tested and proven to work on public repositories .

Found this article helpful? Follow me on Twitter

Top comments (5)

Collapse
 
marcomoscatelli profile image
Marco Moscatelli

Nice tutorial mate!

Collapse
 
enricog profile image
EnricoG

What if my repository on github is private?

Collapse
 
ttquoccuong profile image
ttquoccuong

use ssh keygen

Collapse
 
mary_12 profile image
Lawal Mary

So helpful, thank you ๐Ÿ˜Š

Collapse
 
shaz3e profile image
Shahrukh A. Khan

Auto deploy doesn't work I had to manually Pull & Deploy I created .cpane.yml file inside public_html any further help in this.