How to Deploy from a GitHub Repository in cPanel
Can I deploy from GitHub on cPanel hosting? Yes. "Git Version Control" in cPanel copies (clones) your GitHub repository into your hosting account and brings in later changes with one button. A public repository needs nothing else. A private repository needs a deploy key, which takes a few minutes to set up.
Clone a public repository
- In cPanel open "Git Version Control" and click Create.
- Keep Clone a Repository switched on.
- Clone URL: your repository's address, for example
https://github.com/yourname/yourapp.git. - Repository Path and Repository Name are filled in for you, for example
repositories/yourapp. Note the path: it is where your files will be. - Click Create. cPanel clones the repository in the background; a small one is there within seconds.
If cPanel shows "Your system administrator must enable shell access to allow you to view clone URLs", you can ignore it. It concerns copying from your hosting account, not cloning from GitHub.
Clone a private repository
GitHub must be able to recognise your hosting account. That is done with a deploy key: an SSH key without a password. cPanel's own key generator always asks for a password, which Git cannot use, so create the key in the terminal:
- Ask us to enable SSH on your account. It is free and done within one working day: open a support ticket.
- Open "Terminal" in cPanel, or connect by SSH, and run:
The second command shows the public half of the key, one line that begins with
ssh-keygen -t ed25519 -N "" -C "deploy" -f ~/.ssh/id_ed25519 cat ~/.ssh/id_ed25519.pubssh-ed25519. Copy that line. - On GitHub open your repository, then Settings, Deploy keys, Add deploy key. Paste the line and save.
- In cPanel follow the steps for a public repository, but use the SSH form of the address as the Clone URL:
[email protected]:yourname/yourapp.git.
cPanel accepts GitHub's host key by itself on the first clone.
Run the code as a Node.js app
Set the app up as in How to deploy a Node.js app in cPanel, and give the Repository Path, for example repositories/yourapp, as the Application root.
- Keep
node_modulesout of the repository. cPanel installs the packages itself with Run NPM Install, and the install stops if that folder is present. - For Next.js, most repositories leave out the built
.nextfolder, and the build does not run on shared hosting. Build on your computer and upload the.nextfolder into the same place. See How to deploy a Next.js app in cPanel.
Bring in later changes
- Push your changes to GitHub as usual.
- In cPanel open "Git Version Control", click Manage beside the repository, open the Pull or Deploy tab and click Update from Remote.
- For a Node.js app, open "Setup Node.js App" and click RESTART. If
package.jsonchanged, click Run NPM Install first.
Still stuck? Open a support ticket or start a live chat. See the plans on our Node.js hosting page.
Related: Fix the Git error "Not possible to fast-forward, aborting" and Terminal access in cPanel.