Skip to content

Knowledgebase

Deploying a cPanel Git repository with .cpanel.yml

cpanel-whm, development

A .cpanel.yml file defines deployment tasks for a cPanel-managed Git repository. Treat those tasks as executable release instructions: they can overwrite live files, so review the destination and data exclusions before enabling automatic deployment.

Check access and requirements

Back up the application and database, prepare a staging destination and identify files that must persist outside releases, such as user uploads and environment credentials. Choose push or pull deployment deliberately because their triggering behaviour differs.

01 Deploy a cPanel Git repository with .cpanel.yml

  1. Create or clone the cPanel-managed repository and confirm its branch and current commit. Keep its working copy clean.
  2. Add a valid .cpanel.yml at the repository root with a deployment section and tasks list. Start with explicit copies of known release files into a verified staging directory.
  3. Commit the deployment file. Review every command and path; avoid blanket deletion or copying secrets from the repository into public access.
  4. For pull deployment, open Manage > Pull or Deploy, choose Update from Remote, then Deploy HEAD Commit. Push deployment can trigger automatically when code is pushed to the managed repository.
  5. Inspect deployment output and test the application before applying the proven process to production. Record the deployed commit and rollback method.

02 Example: deploy two static files to a staging directory

For a test repository containing index.html and styles.css, first create an empty permitted staging directory that the hosting account can write. Replace CPANEL_USER and the destination below with your actual staging path. Commit this file as .cpanel.yml at the repository root:

Code or configuration example
---
deployment:
  tasks:
    - /bin/cp index.html /home/CPANEL_USER/deploy-preview/index.html
    - /bin/cp styles.css /home/CPANEL_USER/deploy-preview/styles.css

Each task copies one named release file and can replace that file at the destination. Keep uploads and private configuration outside the release-file list. For pull deployment, fetch the reviewed commit with Update from Remote, then use Deploy HEAD Commit. Inspect the output and verify both files at the staging destination before adapting the process for the live application.

Confirm the expected result

The destination should contain the intended release, uploads should remain intact, and application configuration should still reference the correct environment. Verify more than the homepage.

Resolve setup problems

If a task fails, inspect the first error and the actual destination state before rerunning. Tasks executed before the failure may already have changed files. Restore or redeploy a known-good release through the prepared recovery process.

Does deployment run database migrations automatically?

Only if your tasks explicitly run them. Plan database migrations separately and check backward compatibility before a code rollback. Git history does not preserve live orders or uploaded files unless you built a separate backup process.

Was this answer helpful?

Need a little more help?

Our support team can help you find the next step.

Contact support