Deploying to cPanel using git
Monday, February 15th, 2021 | Programming
cPanel now has support for deploying via git. Here is a quick guide on deploying PHP applications.
Upgrade Composer
The Composer version is old and will need an upgrade. To do this, you need to log into the server as root and run:
composer self-update
Install your SSH key
To avoid having to enter your password every time you push, log into cPanel and add your public SSH key. You can paste the id_rsa into the box and leave the name as default. Once added, go to the manage key and activate it.
Create a git repo
In cPanel, go into the git section and create a new repo. You can place it anywhere so perhaps a good place to put it is:
/home/username/git/repo-name
Add a remote
Back on your own computer, add the new cPanel repo as a remote.
git remote add cpanel ssh://username@example.com/home/username/git/repo-name
Add a cPanel config file
If you need to run any additional tasks, add a .cpanel.yml file to the root of your repo.
deployment:
tasks:
- composer install
- /bin/cp -a /home/username/git/repo-name/public /home/username/public_html
5. Add a .cpanel.yml script
Push your code
Do a standard git push to deploy.
git push cpanel master
You can find the logs in /home/username/.cpanel/logs/ to find out if everything went as planned.
cPanel now has support for deploying via git. Here is a quick guide on deploying PHP applications.
Upgrade Composer
The Composer version is old and will need an upgrade. To do this, you need to log into the server as root and run:
composer self-update
Install your SSH key
To avoid having to enter your password every time you push, log into cPanel and add your public SSH key. You can paste the id_rsa into the box and leave the name as default. Once added, go to the manage key and activate it.
Create a git repo
In cPanel, go into the git section and create a new repo. You can place it anywhere so perhaps a good place to put it is:
/home/username/git/repo-name
Add a remote
Back on your own computer, add the new cPanel repo as a remote.
git remote add cpanel ssh://username@example.com/home/username/git/repo-name
Add a cPanel config file
If you need to run any additional tasks, add a .cpanel.yml file to the root of your repo.
deployment: tasks: - composer install - /bin/cp -a /home/username/git/repo-name/public /home/username/public_html
5. Add a .cpanel.yml script
Push your code
Do a standard git push to deploy.
git push cpanel master
You can find the logs in /home/username/.cpanel/logs/ to find out if everything went as planned.