Deploying code from a GitHub repository directly to your cPanel hosting server is an efficient and secure way to manage your web projects. In this article, you'll learn how to deploy GitHub code to cPanel using Git version control and SSH key authentication, step by step.
โ Why Use Git with cPanel?
- ๐ก Easy project version management
- ๐ Fast updates with one command
- ๐ Secure, key-based deployment (no password required)
- ๐ซ No need for manual uploads via FTP
๐งฉ Prerequisites
Before we begin, make sure you have the following:
- A GitHub account and repository ready
- Access to cPanel with SSH enabled (Namecheap, Hostinger, etc.)
- Your local machine with Git installed
- Basic understanding of SSH and terminal commands
๐ Step-by-Step Setup Guide
๐น Step 1: Enable SSH Access in cPanel
- Log into cPanel
- Search for and open โSSH Accessโ
- Click on โManage SSH Keysโ
- Generate a new SSH key or import your existing public key:
- If generating: set a passphrase (recommended), and click Generate
- Under โPublic Keysโ, click โManageโ โ Authorize
โ This ensures your server will recognize SSH connections from your local machine.
๐น Step 2: Copy Your Public SSH Key to GitHub
- In cPanel, under SSH Access โ Manage SSH Keys, click View/Download on your public key (
id_rsa.pub
) - Copy the entire key contents
- Go to your GitHub profile โ Settings โ SSH and GPG keys
- Click โNew SSH keyโ
- Title:
cPanel Server
- Paste the key
- Click Add SSH Key
๐น Step 3: Log In to cPanel via SSH (Optional Test)
From your local terminal, run:
โ
Example:
ssh your_cpanel_username@yourdomain.com -p your_port
Use the same port shown in your cPanel's SSH Access section (often 21098
on Namecheap).
๐น Step 4: Create or Choose a Deployment Folder
Example: a subdomain like api.content.com
points to:
/home/yourcpanelusername/api.content.com
You can deploy into:
-
public_html/
for your main site - Or any subdomain directory
๐น Step 5: Prepare the Folder for Git
cd ~/api.content.com
If the folder already contains files, back them up:
mkdir _backup
mv * .[^.]* _backup 2>/dev/null
This ensures the folder is clean for Git.
๐น Step 6: Clone Your GitHub Repository
Now clone your repository directly:
git clone git@github.com:yourusername/your-repo.git .
The
.
clones the repo into the current folder.
If successful, your files are now deployed into your live cPanel server.
๐น Step 7: Set Up Git Remote for Future Pulls (Optional)
You can update the remote origin like this:
git remote set-url origin git@github.com:yourusername/your-repo.git
And later, pull new changes:
git pull origin main
Replace main
with your actual GitHub branch if different.
๐ Optional: Use cPanel Git Version Control GUI
cPanel also includes a Git GUI:
- Go to โGit Version Controlโ in cPanel
- Click Create
- Paste your GitHub repo URL
- Choose deployment path (e.g.,
public_html/project
) - Click Create
โ This allows you to deploy code with a click from the cPanel dashboard.
โ ๏ธ Tips & Warnings
Tip | Description |
---|---|
git pull doesn't work? |
Make sure the folder is a valid Git repo (git status ) |
Permission denied? | Your SSH key may not be authorized or added to GitHub |
Avoid FTP | Itโs slow, unsecure, and outdated |
Backup before deploying | Use _backup or git stash to avoid overwriting live files |
๐ฏ Conclusion
With this setup, you now have:
โ
SSH access to your server
โ
Git version control linked to GitHub
โ
Ability to deploy code into any subdomain or folder easily
Whether you're managing a simple portfolio or a full API backend, this Git + SSH workflow on cPanel will save you time, effort, and stress.
๐ง Have Questions?
Drop a comment below or reach out if you need help with:
- Auto deployment scripts
- GitHub Actions + cPanel
- Laravel/Next.js app deployment to cPanel
๐ฅ Stay productive, stay version-controlled!
Top comments (0)