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.

Automate Application deployment

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.

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

 

 

  1. Select Create button

 

  1. On the next screen

 

  1. Disable the “Clone a Repository” Option
  2. Enter a valid directory name (which is in your CPanel file path, usually starts with “/home//public_html/”) in the “Repository Path” field. This could be a non-existing directory or an existing directory with or without files.
  3. Enter a name for your new Repository
  1. For an Existing Project
    1. Go to your local repository sub-directory

 

  1. Create a file named .cpanel.yml

deployment:

  tasks:

    – export DEPLOYPATH=/home//public_html/

    – /bin/cp  -r * $DEPLOYPATH

Normally, Cpanel 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.

 

  1. Run in your local repository
    1. git remote add origin <ssh://repository-path>

 

  1. Then run
    1. git add .
    2. git commit –m “Commit Message”
  • git push -u origin master
    1. if you receive a denyCurrentBranch error then
      1. SSH into your remote directory
      2. Run

git config denyCurrentBranch UpdateInstead

  1. Then run

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

 

 

 

 

Some possible errors that you may encounter 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

 

—–

 

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

—–

 

 

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 repository to your local directory and work normally as you would using the first method shown above.

 

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