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-
- Direct to Git Version Control-
- Select “Git version control” sub-option under “Files” section.
- The GVC enables you to set up deployment for your repositories managed by cPanel.
- View or link your repositories-
- After clicking on GVC, you will enter a new page; here you can manage your repositories.
- If you have already linked a repository from GitHub to cPanel, that’s fine; otherwise, you can create one.
- Clone (Duplicate) your Repository-
- Click on the “Create” button.
- A form type screen will open up. Fill in the details such as “Clone URL”, “Repository Path”, and “Repository Name”.
- The Clone URL relates to your remote repository’s URL, which should initiate with either http://, https://, ssh://, or git://.
- 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.”
- Manage Repositories-
- 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.
- You will find a list of all repositories currently linked to cPanel from Git. Click “Manage” to proceed to the next step.
- Pull or Deploy-
- Select the “Pull or Deploy” tab.
- Click on “Update from Remote” button.
- Click on “Deploy HEAD Commit”.
This way, an effective deployment of a remote repository to cPanel occurs.
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.
- Setting up auto-deployment-
- To implement changes from a cPanel-managed repository, you will need a .cpanel.yml file in the top-level directory of your repository.
- Create the .cpanel.yml file and insert the following code-
##### THIS ALLOWS US TO DEPLOY THE SITE FROM A GIT REPO ######—Deployment:
– 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
- Substitute your-username with your real cPanel username.
- Save and push the changes to your remote repository, then proceed to repeat step 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.