How to automatically deploy from GitHub (Git) to cPanel

October 31, 2023 / cPanel & WHM

This guide demonstrates a rapid method of transferring files from GitHub to cPanel, exclusively relying on GitHub as the primary source. Essentially, we will be fetching data from GitHub.

Throughout this tutorial, we will walk you through the process of configuring and establishing your Git repository for automated deployment to cPanel.

Let us begin, log into your cPanel account-

  1. Direct to Git Version Control-
    1. Select “Git version control” sub-option under “Files” section.
    2. The GVC enables you to set up deployment for your repositories managed by cPanel.
      files
  2. View or link your repositories-
    1. After clicking on GVC, you will enter a new page; here you can manage your repositories.
    2. If you have already linked a repository from GitHub to cPanel, that’s fine; otherwise, you can create one.
      create
  3. Clone (Duplicate) your Repository-
    1. Click on the “Create” button.
    2. A form type screen will open up. Fill in the details such as “Clone URL”, “Repository Path”, and “Repository Name”.
    3. The Clone URL relates to your remote repository’s URL, which should initiate with either http://, https://, ssh://, or git://.
    4. The Repository Path specifies the directory where your repository will be located on cPanel. Typically, the path is home/YOUR-USERNAME/REPOSITORY-NAME. If everything appears to be in order, proceed by clicking on “Create.”
      repository
  4. Manage Repositories-
    1. This step enables the management of our cPanel repositories. To access Git Version Control, follow the path: cPanel > Home > File > Git Version Control. Through GVC, you can set up deployment for repositories managed by cPanel.
    2. You will find a list of all repositories currently linked to cPanel from Git. Click “Manage” to proceed to the next step.
  5. Pull or Deploy-
    1. Select the “Pull or Deploy” tab.
    2. Click on “Update from Remote” button.
    3. Click on “Deploy HEAD Commit”.
      This way, an effective deployment of a remote repository to cPanel occurs.
      pull or display
      However, our goal was to automate the deployment of new changes from GitHub to cPanel. If this is what you are looking for, please proceed.
  6. Setting up auto-deployment-
    1. To implement changes from a cPanel-managed repository, you will need a .cpanel.yml file in the top-level directory of your repository.
    2. Create the .cpanel.yml file and insert the following code-
      ##### 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
    3. Substitute your-username with your real cPanel username.
    4. Save and push the changes to your remote repository, then proceed to repeat step 5.
    5. Note- The code provided above instructs cPanel on the folders and files to pull automatically. Your repository’s file structure may vary.

This was the end of the KB. Hope you understood it well. However, if you have any difficulty, get help from our support staff. They are available 24×7.

Dominos Search