DEV Community

SWAPNIL AHMMED SHISHIR
SWAPNIL AHMMED SHISHIR

Posted on

🚀 How to Deploy GitHub Repositories to cPanel | Git Version Control + SSH Key Setup Step-by-Step Guide 🔥

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

  1. Log into cPanel
  2. Search for and open “SSH Access”
  3. Click on “Manage SSH Keys”
  4. Generate a new SSH key or import your existing public key:
  • If generating: set a passphrase (recommended), and click Generate
    1. 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

  1. In cPanel, under SSH Access → Manage SSH Keys, click View/Download on your public key (id_rsa.pub)
  2. Copy the entire key contents
  3. Go to your GitHub profile → Settings → SSH and GPG keys
  4. 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

If the folder already contains files, back them up:

mkdir _backup
mv * .[^.]* _backup 2>/dev/null
Enter fullscreen mode Exit fullscreen mode

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 .
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

And later, pull new changes:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Replace main with your actual GitHub branch if different.

🔁 Optional: Use cPanel Git Version Control GUI

cPanel also includes a Git GUI:

  1. Go to “Git Version Control” in cPanel
  2. Click Create
  3. Paste your GitHub repo URL
  4. Choose deployment path (e.g., public_html/project)
  5. 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)