Automating Laravel Deployment to cPanel with GitHub Actions
Plan tested Laravel releases for cPanel using GitHub Actions, verified SSH access, production dependencies, controlled migrations, and a rehearsed rollback.
Md Shafin Ahmed
Full-Stack Developer
A repeatable deployment is a sequence you can explain, inspect, and reverse. GitHub Actions can coordinate that sequence for a Laravel application on cPanel, but hosting capabilities differ. This tutorial presents an illustrative Laravel 9 and PHP 8.1 workflow, not a promise that every shared-hosting plan supports SSH, background workers, symbolic links, or atomic releases.
1. Inventory the hosting constraints first
Confirm the web PHP version and the command-line PHP version separately. Shared hosting may expose several binaries, and an SSH session can use a different interpreter from the website. Check required extensions, memory limits, disk space, SSH availability, cron access, and the document-root setting. The public document root must expose Laravel's public directory, not the repository root.
Ask whether the plan supports symlinks and persistent queue workers. If it does not, design an appropriate scheduled queue strategy or choose a more suitable host. Record the actual absolute paths rather than copying another account's directory layout. Test these capabilities in staging before writing deployment automation that depends on features the production account cannot provide.

2. Separate validation from production access
Run syntax checks and application tests before any deployment job can access production credentials. Use a dedicated testing database and isolated mail, cache, and queue configuration. Never point CI tests at the production database. Commit dependency lockfiles and prepare application dependencies through an approved build process; these article examples do not install packages or require npm to run the site.
The workflow below is a minimal syntax gate, not a complete deployment pipeline. Extend it with your existing dependency-preparation and test jobs before treating a release as verified. The checkout action version is readable for illustration; review and pin third-party actions to approved full commit identifiers in a hardened pipeline. A successful lint does not prove that migrations or business behaviour are safe.
name: Laravel syntax gate
on:
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
syntax:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Verify interpreter
run: php -v
- name: Check application PHP syntax
shell: bash
run: |
set -euo pipefail
find app database routes tests -type f -name '*.php' -print0 \
| xargs -0 -r -n 1 php -l3. Establish SSH trust without shortcuts
Create a deployment identity with only the permissions needed for the release directory. Store its private key in a protected GitHub environment secret, and restrict access to that environment through review rules. Do not share a personal administrator key across projects. Rotate deployment credentials when ownership changes or a runner exposure is suspected.
Obtain the server's SSH host-key fingerprint through an independently trusted channel, such as the hosting provider's authenticated control panel or support process. Record the verified known-hosts entry as protected configuration. Do not disable host-key validation to make a pipeline green. An unverified key collected during the same connection attempt does not establish that you reached the intended server.
4. Use a narrow remote deployment entry point
Keep release logic in a reviewed server-side script or equivalent controlled hosting mechanism. A deployment job should select an approved immutable revision or artifact, not run arbitrary commands assembled from request text. Prevent overlapping releases with workflow concurrency and a server-side lock. Keep secrets out of shell tracing and avoid printing environment files during debugging.
This invocation assumes a protected, ephemeral Linux runner with three environment secrets supplied by the deployment job, a standard SSH port, and a pre-reviewed remote script. The known-hosts value must already be verified. It intentionally leaves release operations to that script rather than presenting an unsafe universal deployment command. Adapt the fixed remote path to your hosting account.
set -euo pipefail
: "${DEPLOY_PRIVATE_KEY:?Protected deployment key is required}"
: "${DEPLOY_KNOWN_HOSTS:?Verified known-hosts entry is required}"
: "${DEPLOY_TARGET:?Approved user@host target is required}"
case "$DEPLOY_TARGET" in
-*) exit 2 ;;
esac
umask 077
ssh_dir="$(mktemp -d)"
trap 'rm -rf -- "$ssh_dir"' EXIT
printf '%s\n' "$DEPLOY_PRIVATE_KEY" > "$ssh_dir/key"
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$ssh_dir/known_hosts"
ssh -i "$ssh_dir/key" \
-o BatchMode=yes \
-o IdentitiesOnly=yes \
-o StrictHostKeyChecking=yes \
-o UserKnownHostsFile="$ssh_dir/known_hosts" \
"$DEPLOY_TARGET" '/home/ACCOUNT/bin/deploy-approved-release'5. Prepare releases without exposing private files
Where supported, stage each release in a separate directory and connect shared writable storage and protected environment configuration deliberately. Build production dependencies from the lockfile using the correct PHP runtime in your approved process. Never copy a developer's environment file into production. Ensure logs, private uploads, and credentials cannot be served through the public document root.
Refresh configuration and view caches only after the production environment is available. Laravel configuration caching means environment access should occur in configuration files rather than scattered runtime calls. Check directory ownership instead of granting broad write permissions. Keep a previous release available, but do not duplicate secrets into world-readable archives or leave backup files beneath public storage.

6. Treat migrations as a separate safety decision
Review schema changes for compatibility with both the old and new application versions. Prefer an expand-and-contract approach: add new structures, deploy compatible code, backfill carefully, and remove obsolete structures in a later release. A database migration that drops a column cannot be made harmless merely by switching a symlink back to older code.
Rehearse migrations against a representative staging copy with sensitive data removed. Measure expected locks and consider a maintenance window for disruptive changes. Back up the database and verify restoration before relying on that backup. Make production migration execution an explicit approved step. Avoid treating migration rollback as a universal recovery mechanism, especially after users have written new data.
7. Verify the public switch and background work
Check a deliberately implemented health endpoint, a public page, authentication, an authorised dashboard, and asset delivery after the release switch. Laravel 9 does not automatically provide every health endpoint shown in newer framework examples. Keep any health response minimal and free of credentials, stack traces, or private infrastructure details.
Restart or recycle queue workers through the host's supported process so they load the new code. Verify the scheduler is running and that failed jobs remain observable. Confirm mail delivery using an appropriate test account, not a real customer broadcast. Watch application and web-server errors during the first normal requests, and compare the deployed revision with the approved release record.
8. Rehearse rollback before you need it
Document who can stop a release, switch application code back, and assess database compatibility. Keep the recovery procedure short enough to follow during an incident. A release is complete only after checks pass and someone owns the remaining alerts. Automation should reduce uncertainty, not hide consequential operations behind an unexplained green badge.
- Verify interpreter, extensions, and document root.
- Protect deployment identity and verify host keys.
- Test the release before production access.
- Approve migrations and confirm recoverable backups.
- Check web requests, workers, scheduler, and rollback.
Written by
Md Shafin Ahmed
Laravel, Wix & Flutter developer at HEXBRID, building custom web applications, e-commerce stores, and mobile apps for growing businesses.
More About Me