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…


This content originally appeared on DEV Community and was authored by DEV Community

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 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 3 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

##### 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

  1. Guide to Git™ - How to Set Up Deployment

Found this article helpful? Follow me on Twitter


This content originally appeared on DEV Community and was authored by DEV Community


Print Share Comment Cite Upload Translate Updates
APA

DEV Community | Sciencx (2022-03-10T05:07:23+00:00) How to Automatically deploy from GitHub (Git) to cPanel. Retrieved from https://www.scien.cx/2022/03/10/how-to-automatically-deploy-from-github-git-to-cpanel/

MLA
" » How to Automatically deploy from GitHub (Git) to cPanel." DEV Community | Sciencx - Thursday March 10, 2022, https://www.scien.cx/2022/03/10/how-to-automatically-deploy-from-github-git-to-cpanel/
HARVARD
DEV Community | Sciencx Thursday March 10, 2022 » How to Automatically deploy from GitHub (Git) to cPanel., viewed ,<https://www.scien.cx/2022/03/10/how-to-automatically-deploy-from-github-git-to-cpanel/>
VANCOUVER
DEV Community | Sciencx - » How to Automatically deploy from GitHub (Git) to cPanel. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/10/how-to-automatically-deploy-from-github-git-to-cpanel/
CHICAGO
" » How to Automatically deploy from GitHub (Git) to cPanel." DEV Community | Sciencx - Accessed . https://www.scien.cx/2022/03/10/how-to-automatically-deploy-from-github-git-to-cpanel/
IEEE
" » How to Automatically deploy from GitHub (Git) to cPanel." DEV Community | Sciencx [Online]. Available: https://www.scien.cx/2022/03/10/how-to-automatically-deploy-from-github-git-to-cpanel/. [Accessed: ]
rf:citation
» How to Automatically deploy from GitHub (Git) to cPanel | DEV Community | Sciencx | https://www.scien.cx/2022/03/10/how-to-automatically-deploy-from-github-git-to-cpanel/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.