Deploying from Git on cPanel: Git Version Control and .cpanel.yml
Uploading changed files one by one over FTP works until the day you forget one, overwrite the wrong version or cannot remember what changed. cPanel has a built-in alternative: Git Version Control, combined with a small file called .cpanel.yml that tells cPanel what to do with your code after each push.
This guide explains both deployment methods cPanel supports, shows working .cpanel.yml examples for static sites and PHP apps, and covers the errors you are most likely to meet.
How Git deployment works in cPanel
cPanel keeps the repository in a folder you choose, for example /home/USER/repositories/mysite. That folder is not your website. When you deploy, cPanel runs the commands listed in .cpanel.yml, which copy the files you choose into the live folder, such as public_html.
There are two ways to trigger a deployment:
- Push deployment: you push from your computer directly to the repository on cPanel. A hook that cPanel adds to every repository it manages runs
.cpanel.ymlautomatically. - Pull deployment: you push to GitHub, GitLab or another remote, then click Update from Remote and Deploy HEAD Commit in cPanel.
Keeping the repository outside public_html matters: the .git folder contains your full history, and it should never be reachable from a browser.
Requirements
- Git Version Control in cPanel, found in the Files section. If you are new to the interface, our cPanel user guide for beginners shows where each section is.
- Shell access on the account, so you can push over SSH and use keys. Our SSH basics guide explains the connection itself.
- A
.cpanel.ymlfile committed in the top level of the repository. - At least one branch and a clean working tree. If the repository on the server has uncommitted changes, cPanel hides the deployment options.
Method 1: push deployment to a cPanel repository
- In cPanel, open Git Version Control and click Create.
- Turn off the Clone a Repository toggle to create an empty repository.
- Enter a Repository Path such as
repositories/mysiteand a Repository Name, then click Create. - Copy the clone URL that cPanel shows. It looks like
ssh://USER@example.com/home/USER/repositories/mysite. If your host uses a different SSH port, add it after the hostname, for exampleexample.com:2222. - Add your public SSH key in cPanel under SSH Access, then authorize it.
- On your computer, add the server as a remote and push:
git remote add cpanel ssh://USER@example.com/home/USER/repositories/mysite git push cpanel main
If .cpanel.yml is in the pushed commit, the deployment starts automatically after the push. Every later git push cpanel main repeats the same tasks.
Method 2: pull deployment from GitHub or GitLab
For a private repository, the server needs its own key that GitHub accepts. A read-only deploy key is the safest choice.
- In the cPanel Terminal or over SSH, create a key with no passphrase, because cPanel cannot type one for you:
ssh-keygen -t ed25519 -f ~/.ssh/mysite_deploy -N "" -C "deploy key for mysite" - Tell SSH to use that key for GitHub by adding this to
~/.ssh/config(create the file with permissions 600 if it does not exist):Host github.com IdentityFile ~/.ssh/mysite_deploy - In GitHub, open the repository, go to Settings, Deploy keys, Add deploy key, and paste the contents of
~/.ssh/mysite_deploy.pub. Leave write access off. - Test the connection and accept the host key when asked:
ssh -T git@github.com - In Git Version Control, click Create, keep Clone a Repository on, enter the SSH clone URL (
git@github.com:yourname/mysite.git) and a repository path, then click Create. - To deploy later, click Manage next to the repository, open the Pull or Deploy tab, click Update from Remote, then Deploy HEAD Commit.
Which method should you use?
Choose push deployment if you work alone or in a small team and do not need GitHub's pull requests and reviews. It is the shortest path: commit, push, done. The repository on the server also acts as an extra copy of your history.
Choose pull deployment if your code already lives on GitHub or GitLab, several people contribute, or you want a review step before anything reaches the server. The extra click in cPanel becomes a deliberate release moment.
Either way, a typical day looks the same:
- Work on a branch locally and test the change.
- Merge into the branch that the server tracks, usually
main. - Push, or update from the remote and deploy in cPanel.
- Open the site and check the pages you changed.
Writing .cpanel.yml
The file is YAML with a list of shell commands under deployment and tasks. The commands run from the repository folder, so relative paths point into your code.
A static site
---
deployment:
tasks:
- export DEPLOYPATH=/home/USER/public_html/
- /bin/cp index.html $DEPLOYPATH
- /bin/cp -R css $DEPLOYPATH
- /bin/cp -R js $DEPLOYPATH
- /bin/cp -R images $DEPLOYPATH
cPanel's documentation warns against copying everything with a wildcard such as *, because that can deploy the .git folder. If you prefer one command for the whole tree, use rsync with explicit exclusions:
---
deployment:
tasks:
- export DEPLOYPATH=/home/USER/public_html/
- /usr/bin/rsync -a --exclude=.git --exclude=.cpanel.yml --exclude=README.md ./ $DEPLOYPATH
Avoid rsync's --delete option on public_html. It removes anything not in the repository, including files other tools placed there.
A PHP application such as Laravel
---
deployment:
tasks:
- export APPPATH=/home/USER/laravel/
- /usr/bin/rsync -a --exclude=.git --exclude=.env --exclude=storage ./ $APPPATH
- cd $APPPATH && composer install --no-dev --optimize-autoloader
- cd $APPPATH && /usr/local/bin/php artisan migrate --force
- cd $APPPATH && /usr/local/bin/php artisan optimize
The .env file and the storage folder are excluded so that production settings, uploads and logs are never overwritten. Check the paths to composer and php with which composer and which php in the Terminal.
A Node.js app
For an app created in Setup Node.js App, copy the code to the application root, install packages inside the app's environment and touch the restart file as the last task:
---
deployment:
tasks:
- export APPPATH=/home/USER/myapp/
- /usr/bin/rsync -a --exclude=.git --exclude=node_modules --exclude=.env ./ $APPPATH
- source /home/USER/nodevenv/myapp/24/bin/activate && cd $APPPATH && npm ci --omit=dev
- /bin/touch /home/USER/myapp/tmp/restart.txt
Checking what happened
For both methods, cPanel writes a log for each run to /home/USER/.cpanel/logs/, in files named like vc_TIMESTAMP_git_deploy.log. Open the newest one when a deployment does not do what you expected.
| Problem | Likely cause | Fix |
|---|---|---|
| No deploy option in cPanel | Missing .cpanel.yml or uncommitted changes on the server | Commit the file at the top level; do not edit files inside the server repository |
| Permission denied (publickey) | Key not authorized in cPanel, or deploy key missing in GitHub | Authorize the key in SSH Access, or add the deploy key |
| Host key verification failed | The server has never connected to GitHub | Run ssh -T git@github.com once and accept the key |
| Push succeeds but site unchanged | Wrong deploy path, or cp used without -R for folders | Check the paths and read the deploy log |
| YAML error | Tabs instead of spaces, or a stray colon | Indent with spaces and validate the file before committing |
Good practices
- Never commit secrets. Keep
.envfiles and API keys on the server only. - Deploy to a test subdomain first. Our article on staging environments shows how to set one up.
- Roll back with Git, not by hand: revert the bad commit, push again and let the same tasks run.
- Do not edit files in the live folder directly. The next deployment will overwrite them.
Frequently asked questions
Can I deploy automatically from GitHub without clicking anything?
cPanel's pull method needs a click. For fully automatic deploys from GitHub, either push to both GitHub and the cPanel repository, or use a GitHub Actions workflow that connects over SSH and runs the deployment.
Can I use HTTPS instead of SSH keys?
Public repositories can be cloned over HTTPS without any key. Private repositories need authentication, and SSH deploy keys are the simplest secure option.
Should the repository be inside public_html?
No. Keep it in a separate folder such as repositories and let .cpanel.yml copy only the files the site needs.
Is this better than FTP?
For anything you change often, yes. Every deployment is a known commit, and you can see exactly what changed. FTP still has its place for one-off uploads, as covered in our FileZilla guide.
Hostinq.com shared hosting runs cPanel on LiteSpeed Enterprise and CloudLinux, with nightly backups and support 09:00-03:00. You can compare plans on the shared hosting page, and our support team can confirm SSH access for Git deployments on the plan you choose.