Development and databases
Automating Git deployment tasks with the .cpanel.yml file
The .cpanel.yml file defines the tasks that cPanel's Git deployment runs. It must be versioned in the repository root, with exactly that name.
If you would rather set up scripts, releases and automation from the client area, see Deploy+.
Example for two static files
This example copies two files from the repository to a test folder that must already exist. Replace the path with yours and first check that it does not contain files with those names that you want to keep:
--- deployment: tasks: - /bin/cp -- index.html style.css /home/usuario_cpanel/public_html/pruebas/
The copy may overwrite the two destination files. It does not synchronise a whole website, does not delete old files and does not change both files atomically. For several dependent operations, call a script with error checking, as in the Laravel example.
Push and pull: when it runs
Push to the cPanel repository: cPanel can run the tasks through its hook if the repository meets the deployment requirements. Confirm the repository and the branch you are pushing code to.
Pull from GitHub or another remote: in Git Version Control > Manage > Pull or Deploy, Update from Remote updates the clone. You then need to use Deploy HEAD Commit to run .cpanel.yml. A push to GitHub does not automatically start this process in cPanel.
Trigger it from the API or cron
For a repository already managed by cPanel:
/usr/local/cpanel/bin/uapi --output=jsonpretty VersionControlDeployment create \ repository_root='/home/usuario_cpanel/repositories/proyecto'
The call requests a deployment of the code that is in the repository; it does not replace the step of updating from the remote. Check result.status and follow the log or the task until you know its final result.
Do not add the call to cron without a control that prevents overlaps for the whole run. A lock that is released when the API returns the queued task may end before the deployment does.
Check and undo
After the deployment, check the logs, the commit and the content being served. A task may have changed data before failing; do not assume everything has been undone.
Prepare a way to recover overwritten content and keep persistent files separately. For database changes, define a specific rollback: going back to a commit does not recover data a task has deleted.
You may also find useful
- Deploy WordPress and Laravel on cPanel with Deployer Set up release-based deployments with Deployer, configure shared files and check what a rollback can...
- Git, graphical interface with cloning, history and automatic deployment Manage Git repositories from cPanel; create or clone projects, update branches, deploy with .cpanel....
- Deploy Laravel from GitHub with Git and cPanel's .cpanel.yml Set up a Laravel deployment workflow from GitHub to cPanel with dedicated keys, .cpanel.yml, verifie...
- Host React, Vue and static websites connected to external APIs Check whether your JavaScript frontend fits on shared hosting, connect it to Supabase, Firebase or o...
Something wrong or out of date? Tell us and we will review it.