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.
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
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.
The Clone URL refers to your remote repository URL. It must begin with either
http://
,https://
,ssh://
orgit://
Example: https://github.com/Eunit99/eunit99.gitThe 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"
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.
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.
- Click on Pull or Deploy tab
- Click on Update from Remote
- Click on Deploy HEAD Commit
🎆✨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:
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
- 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
This tutorial has been tested and proven to work on public repositories .
Top comments (5)
Nice tutorial mate!
What if my repository on github is private?
use ssh keygen
So helpful, thank you 😊
Auto deploy doesn't work I had to manually Pull & Deploy I created .cpane.yml file inside public_html any further help in this.