Easy CI/CD on Shared hosting using CPanel Git Version in less than 5 minutes

Setup Cpanel Git Version

It is frustrating to FTP files every time we change some code in our application. Read on to know how to set up a Continuous Deployment using CPanel Git Version on a shared server hosting or a VPS.

Automate Application deployment

This article explains how to automate your file deployment to a shared (or VPS) hosting with CPanel.

This article assumes you have access to CPanel through your webhost (like GoDaddy for example) and you have some basic knowledge of Git Operations and how Git works. Here is a good place to start off on git.

By using this method you can skip using the CPanel File Manager/FTP /SSH to upload files and you can easily git push files to your web host using some basic Git commands. This method works for all types of applications from simple HTML/CSS to WordPress or other CMS to any other type of Web Application which are capable of running on your Cpanel Hosted service.

Explanation

The following tutorial requires you to have SSH Access to your CPanel Account. Know how to setup SSH Access on CPanel

If your source is a local directory

Open CPanel
Select Git Version Option

Cpanel Image

  1. Select Create button
  2. On the next screen
  • Disable the “Clone a Repository” Option
  • Enter a valid directory name (which is in your CPanel file path, usually starts with “/home/public_html/<path-to-repo>”) in the “Repository Path” field. This could be a non-existing directory or an existing directory with or without files.
  • Enter a name for your new Repository
  • Click create and you are done.

Copy the ssh://cpanel-git-remote-repo-path-url

For an Existing Project

  • Go to your local repository sub-directory
  • Create a file named .cpanel.yml

deployment:
tasks:
- export DEPLOYPATH=/home/public_html/<path-to-remote-repo>
- /bin/cp -r * $DEPLOYPATH

Normally, Cpanel Git Version prefers that you not use ‘*’ to copy files in the .cpanel.yml file, but instead use single file names. (But, this way works simply because when you are not exactly sure which file you are going to upload from your local repository, it becomes difficult to upload selected files.)

c. Get the Run the following commands in your local repository

git remote add origin <ssh://cpanel-git-remote-repo-path-url>

d. Then run

git add .
git commit –m “Commit Message”
git push -u origin master

if you receive a denyCurrentBranch error then

SSH into your remote directory and run

git config denyCurrentBranch UpdateInstead

Then run

git push –u origin master --exec=/usr/local/cpanel/3rdparty/bin/git-receive-pack

Some possible errors that you may encounter while setting up CPanel Git Version and their solutions:

Error:
fatal: bad config value for 'receive.denycurrentbranch' in ./config
fatal: Could not read from remote repository.

Solution:
Run
git config denyCurrentBranch UpdateInstead on your remote repository

Then run

git push –u origin master --exec=/usr/local/cpanel/3rdparty/bin/git-receive-pack

on your local repository as described in Cpanel’s post to Push local changes to the hosted repository

Error:
Server unable to read htaccess file, denying access to be safe

Solution:
Change directory permissions of ‘public_html’ and any other sub-directory leading to your <cpanel-git-repo-path> to 755

Error:
! [remote rejected] master -> master (Working directory has unstaged changes)
error: failed to push some refs to...

You may encounter this error often when you are trying to git push files to the remote

Solution:
Create a file in your remote repository inside the ‘.git/hooks’ called push-to-checkout (if not exists) and add the following code in the file.

!/bin/sh
set -ex
git read-tree --reset -u HEAD "$1"

save the file and exit and run

chmod +x push-to-checkout

to change permissions of the file to executable

If your source is a remote repository

If your source is a remote repository like Github/Bitbucket or any other, the steps are similar to the above with just 1 additional step of checking On the ‘Clone a Repository’ button and adding the remote repository address in the ‘Clone URL’ field.

Then you can actually clone the Cpanel Git repository to your local directory and work normally as you would using the first method shown above.

Hope you liked this article about easily setting up CI/CD on Cpanel Git, feel free to get back to me for any doubts or clarifications, I’ll try to help you out as much as I can.

If you think this is too much for you to handle, do not worry, Triolutions is here to help you out with CI/CD on Cpanel git or if required can set you up with AWS cloud too.

Share on facebook
Share on twitter
Share on whatsapp
Share on linkedin
Share on google

2 Responses

Leave a Reply

Your email address will not be published.