Website deploy from git in web hosting with cpanel.

Website deploy from git in web hosting with cpanel.

Public repository only

·

2 min read

Cpanel has a option to access git repository and pull a specific branch to deploy to specific folder. Suppose you have a website in development and maintain with version control with git and want to deploy code from github or gitlab.

steps:

  1. Go to ssh access from cpanel. Click on generate a new key. Fill up the form and press generate key. A public and private key pair generated.

1601098021111.png

  1. Authorize the key from the list of keys.

1601096133925.png

  1. Click on the view/download link in the public key section and copy the key and added into the github repository.

  2. To add public key in github repository, go to you repository page on github then click on settings and find a option deploy key. add that public key into deploy key section. be aware you add this public key in specific repository page not your profile and only give access to read not write. otherwise if anyway your server compromise then your github account will be in risk.

1601096432091.png

  1. So now you ready to deploy your code in the hosting server. To do that you copy the https clone url. for me its github.com/ziauddin/nzianxyz.git

  2. Then again go to your cpanel git version control section. find the create button and paste you github cloning url and two other field will automatically filled up based on repository name. Check repository path carefully, by default cpanel create a folder under home directory / repository but if you want to deploy the code into public_html then change to public_html and save it.

1601098075410.png

  1. Now you can see one repository listed in git version control section. click on manage button and choose which branch you want to deploy.

1601098666339.png

That's all. you successfully deploy your github code to your web server and every time you push the repository which you deploy into cpanel will automatically pull the code form github repository.