cpanel-deploy
v1.1.0
Published
Set up GitHub Actions deploys to cPanel in one command, with database migrations, SQL updates, backups and database tools. No SSH needed.
Maintainers
Readme
cpanel-deploy
Set up GitHub Actions deploys to cPanel in one command. Migrations, SQL updates, backups and database tools included. No SSH needed.
No more copying the same workflow file into every repo and typing CPANEL_HOST, CPANEL_USERNAME and CPANEL_PASSWORD into GitHub by hand.
npx cpanel-deployWebsite: https://saikat.polapain.net/cpanel-deploy
What it does
Run it inside your project folder and answer a few questions:
- Pick a cPanel account you saved before, or add one. The FTP login is tested right away.
- Pick the branch that should deploy (a manual "Run workflow" button is added too).
- Browse the server folders over FTP and choose where files go, like
public_html/live/. - Confirm build steps. If it finds
composer.jsonit offerscomposer install, ifpackage.jsonhas abuildscript it offersnpm run build. - Database steps (optional). For Laravel or other PHP projects it can run migrations and SQL updates after every deploy, with a backup first.
- Done. It writes
.github/workflows/cpanel-deploy.yml, uploads the secrets to GitHub and commits the files. Push and it ships.
Commands
| Command | What it does |
| --- | --- |
| npx cpanel-deploy | Interactive menu |
| npx cpanel-deploy init | Set up deploys for the current repo. Run again to add another target, like staging. |
| npx cpanel-deploy profiles | Add, edit, test or delete saved cPanel accounts |
| npx cpanel-deploy db | Create a database, upload or download one, run SQL, back up, bring the site back up |
| npx cpanel-deploy secrets | Upload the secrets again (changed password, new host) |
| npx cpanel-deploy doctor | Check Node, Git, GitHub CLI and the current repo |
Requirements
- Node.js 20.12 or newer
- Git
- One of these, so secrets can be uploaded for you:
- GitHub CLI logged in with
gh auth login(easiest), or - a fine grained token with Secrets: Read and write on the repo
- GitHub CLI logged in with
Without either, the tool still writes the workflow and tells you which secrets to add.
Database steps on every deploy
Turn them on during init. After the files upload, GitHub calls a small signed PHP file on your server that:
- checks what's pending: Laravel migrations, and new
.sqlfiles indatabase/updates/ - if nothing is pending, only clears config, route and view caches (no downtime, no backup)
- otherwise puts the app in maintenance mode (Laravel), backs up the database, runs the new SQL files once each, runs
php artisan migrate --force, clears caches and brings the app back up
If something fails, the GitHub run turns red and the site stays in maintenance mode (or comes back up, you choose during setup). Backups are kept in storage/app/cpanel-deploy-backups/ (last 5).
Small one off changes: drop a file like database/updates/2026_10_27_01_fix_prices.sql in your repo. It runs once, in name order, on the next deploy and is remembered in the cpanel_deploy_updates table. Works for plain PHP projects too (database settings are read from the .env next to the project).
How the hook stays safe: the file name is random, the secret is only in GitHub secrets (never in git), every request is signed with HMAC SHA-256 and expires after 5 minutes. Anything else gets a plain 404. It runs Artisan inside PHP, so it works on hosts that disable exec.
Database tools
npx cpanel-deploy db- Create a database: database, user and a strong password in one go, and optionally written straight into the server
.env - Upload a database: from a
.sql/.sql.gzfile or straight from your local MySQL (XAMPP, Laragon). The server database is backed up first - Download a database: to a
.sql.gzfile, optionally imported into your local MySQL - Run SQL: quick queries on the live database. Anything that isn't a read asks for confirmation first
- Back up now / bring the site back up: when database steps are enabled
How it reaches the database without SSH: with a cPanel API token (cPanel > Security > Manage API Tokens), it allows only your current IP in Remote MySQL, creates a short lived MySQL user for that one database, and removes both when done, even if the session crashes (the next session cleans up). If your host blocks Remote MySQL, it works through the deploy hook instead, on the project's own database.
Data is copied exactly: dates without timezone shifts, big integers and decimals as exact text, JSON as stored, binary columns, emoji. Views and triggers are made portable so they keep working after import.
Multiple targets
Run init again in the same repo and choose "Add another deploy target". A target named staging gets its own file cpanel-deploy-staging.yml and its own secrets CPANEL_STAGING_HOST, CPANEL_STAGING_USERNAME, CPANEL_STAGING_PASSWORD, so live and staging never mix.
Security notes
- Saved accounts live in
~/.cpanel-deploy/config.jsonon your computer, with permissions limited to your user. You can choose not to save a password and type it each time. - Prefer a dedicated FTP account in cPanel limited to the deploy folder, instead of your main cPanel login.
- Choose FTPS (the default). Plain FTP sends the password unencrypted.
- Shared hosts often present a certificate for the server hostname, not your domain. The tool detects this and can set
security: loosefor that account. Using the server hostname from cPanel as the FTP host avoids it.
Generated workflow
Uses SamKirkland/FTP-Deploy-Action, which only uploads files that changed since the last deploy. Example:
name: Deploy to cPanel
on:
push:
branches:
- 'cp-live'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Deploy via FTP
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.CPANEL_HOST }}
username: ${{ secrets.CPANEL_USERNAME }}
password: ${{ secrets.CPANEL_PASSWORD }}
protocol: ftps
local-dir: './'
server-dir: 'public_html/live/'Development
npm install
npm test
node bin/cpanel-deploy.jsEnvironment variables useful while testing:
CPANEL_DEPLOY_HOMEchanges where accounts are savedCPANEL_DEPLOY_GITHUB_APIpoints the GitHub API calls at a mock server
License
MIT © Moniruzzaman Saikat
