A simple PHP app showing how to set up cPanel auto-deployment with Git and Composer. It uses the Carbon library to display formatted server time and shows PHP version on a basic HTML page served from public_html
.
To get going, you’ll need:
- A cPanel account with Git Version Control enabled
- A remote Git repository (GitHub, GitLab, Bitbucket, etc.)
- PHP 7.4 or higher on your hosting environment
- Composer available on the server (cPanel’s
.cpanel.yml
runs it automatically) - SSH access to your server (optional)
When you add your repo in cPanel’s Git Version Control, cPanel clones it into:
/home/username/repositories/composer-on-cpanel/
But your actual web root is:
/home/username/public_html/
We’ll use .cpanel.yml
to:
- Run Composer
- Copy the fresh build into
public_html
/home/username/
├── repositories/
│ └── composer-on-cpanel/ # your Git repo root
│ ├── composer.json # project dependencies (Carbon)
│ ├── .cpanel.yml # cPanel deployment tasks
│ └── index.php # demo script
└── public_html/ # live site served by Apache
├── index.php # demo script
└── vendor/ # Composer dependencies
-
Configure cPanel
- In cPanel, open Git Version Control.
- Click Clone Repository, paste your repo URL.
- Set Clone Path to
/home/username/repositories/composer-on-cpanel
. - Enable Auto Deploy on the
main
branch.
-
Every push triggers:
- Git pull in
/repositories/composer-on-cpanel
- Composer install (installs Carbon)
- New files copied into
public_html
- Git pull in
Visit your domain to see the formatted Carbon date/time and PHP version.
- Customize
.cpanel.yml
cp commands if you need to preserve files across deploys. - Use rsync instead of cp for better performance and exclude unnecessary files.
- The point of this demo is to show how to set up cPanel auto-deployment with Git and Composer if you don't have SSH access to your server. But optional SSH access is recommended for production use.