Brieflyn
Navigation Menu
Home › Tutorials & How-To › How to Deploy Laravel with Git: A 2026 Guide for Developers

How to Deploy Laravel with Git: A 2026 Guide for Developers

How to Deploy Laravel with Git: A 2026 Guide for Developers
By Brieflyn Editorial Team • Published: August 17, 2026 • 13 min read (2,420 words) • 34 views
Learn how to Deploy Laravel with Git in 2026 with a secure, automated workflow. Follow our step‑by‑step guide to keep code integrity and reduce downtime.

How to Deploy Laravel with Git workflow diagram showing central repository, local development, and production server

How to Deploy Laravel with Git is still the question every PHP team answers in its first sprint of 2026, and the answer has gotten sharper. Pushing a central repository, pulling on the server, and automating the rest with a hook or a CI job is faster than FTP, cleaner than tarball uploads, and auditable in ways a scp command never will be. What changed this year is the threat model: a high-profile supply-chain compromise that hit four packages under the Laravel-Lang organization proved that "Git-based" and "secure" are not synonyms. This guide walks through a deployment workflow that is both fast and hardened against the attacks that emerged through 2025 and 2026.

Overview: What is Git-based Deployment?

Definition

Definition: Git-based deployment is a workflow where a central Git repository acts as the single source of truth, and a server-side mechanism (a hook, a CI runner, or a pull request merge) updates the live application whenever new commits land on a protected branch.

Typical Workflow

The pattern most teams use in 2026 looks like this: a developer commits locally, pushes to a remote such as GitHub or GitLab, opens a pull request, gets a code review, merges to main, and a post-receive hook (or a CI job wired to that merge) runs git pull on the production box, refreshes dependencies, and reloads PHP-FPM. The SitePoint walkthrough on deploying with Git documents the same flow from the early 2010s, but with one important refinement: today, the pull should not be the whole pipeline. It should be one of several automated checks.

Key Benefits

Three benefits justify the approach. You get a full audit trail of every commit that ever reached production. You can roll back by checking out a previous tag. You eliminate the "what changed?" conversation at 2 a.m. because the deploy log is the Git log.

Why Git Deployment Matters in 2026

Close-up of a person holding a Git sticker, emphasizing software development.
Photo by RealToughCandy.com via Pexels. How To Deploy Laravel With Git Technology.

Modern DevOps Trends

The shift-left movement is no longer a slogan. In 2026, security scans, dependency audits, and migration checks all run before code reaches the server. A Git-driven pipeline is the only structure that makes those gates enforceable: if a check fails, the merge is blocked, and the hook on the server never fires.

Security

The Laravel-Lang supply-chain incident, documented in detail by StepSecurity and Rescana, rewrote every Git tag in four repositories (laravel-lang/lang, laravel-lang/http-statuses, laravel-lang/actions, and laravel-lang/attributes) to point at malicious commits. The dropper added a src/helpers.php file to the Composer autoload.files map, so the moment a developer required vendor/autoload.php, the payload executed. BleepingComputer reported that the secondary payload was a roughly 5,900-line credential stealer covering cloud, Kubernetes, Vault, Git, CI/CD, SSH, browser data, and crypto wallets. Any environment that pulled an affected version after 2026-05-22 22:32 UTC must be treated as compromised until proven otherwise.

Compliance & Auditing

For SOC 2 and ISO 27001 audits, a Git-driven deploy gives you something SSH scripts rarely do: an immutable, signed record of who shipped what and when. Pair the repo with signed commits and protected branches, and you have a paper trail auditors accept on first review.

Prerequisites & Environment Setup

Hardware & Hosting Options

Any VPS or managed host that supports SSH, PHP 8.2 or newer, and Git 2.40+ will work. Common picks in 2026: DigitalOcean droplets, AWS Lightsail, GCP e2-medium instances, Azure B2s, or platform-as-a-service options like Railway and Fly.io. Heroku remains viable for prototypes, but the buildpack approach hides the Git hook layer that this guide relies on.

PHP & Composer Requirements

Laravel 11 and 12 require PHP 8.2 minimum, and Laravel 13 (the current stable as of this writing) requires PHP 8.3. Composer 2.7+ is mandatory because earlier versions do not enforce lockfile integrity checks the way modern projects expect. Install Composer from the official site, never from a distribution package, to avoid tampered binaries.

Git & SSH Keys

Generate a dedicated deploy key per environment, not per developer:

ssh-keygen -t ed25519 -C "deploy@production-app" -f ~/.ssh/prod_deploy
cat ~/.ssh/prod_deploy.pub

Add the public key as a read-only deploy key on the repository. Never grant write access to the production key; the server only needs to pull.

Setting Up the Git Repository for Production

Low angle view of a modern playground structure featuring red spheres and steel bars against a clear blue sky.
Photo by Brett Sayles via Pexels. How To Deploy Laravel With Git Concept.

Creating a Bare Repository

On the production server, initialize a bare repo that the live document root will track:

mkdir -p /var/repo/production.git && cd /var/repo/production.git
git init --bare
git config receive.denyCurrentBranch ignore

Branching Strategy

Use a trunk-based model: main is always deployable, feature branches are short-lived, and releases are marked with annotated tags (v1.4.2). Tags double as your rollback targets. After the Laravel-Lang incident, treat every tag rewrite as a security event: subscribe to commit notifications on the tags you depend on.

Access Controls

Branch protection rules on GitHub or GitLab should require at least one approving review, passing CI checks, and signed commits for any merge to main. The deploy key on the server should be a separate, read-only identity with no access to other repositories.

Configuring Laravel for Git Deployments

Environment Variables & .env

Never commit .env. Add it to .gitignore at the project root and keep a .env.example checked in as a template. On the server, place the real .env outside the document root or in a directory readable only by the deploy user, and symlink it into the release.

Optimizing Composer Autoload

Run optimized autoloading after every pull to keep OPcache happy:

composer install --no-dev --optimize-autoloader
php artisan config:cache
php artisan route:cache
php artisan view:cache

Handling Vendor & Assets

Add /vendor, node_modules, and public/storage to .gitignore. Build assets in CI and ship the compiled public/build directory as an artifact, or run npm ci && npm run build on the server if your box has the toolchain. For most teams, CI-side builds are faster and more reproducible.

How to Deploy Laravel with Git: Core Workflow Steps

The canonical pull-from-server pattern uses a post-receive hook. Inside the bare repository at /var/repo/production.git/hooks/post-receive, drop this script:

#!/bin/bash
LIVE="/var/www/production"
git --work-tree=$LIVE --git-dir=/var/repo/production.git checkout -f main
cd $LIVE
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
(php artisan queue:restart) || true

Make it executable with chmod +x post-receive. When developers run git push origin, the hook fires automatically and the live site updates.

Automating Deployment with Git Hooks

Client-Side Pre-Commit Checks

A pre-commit hook on developer machines should run Pint or PHP-CS-Fixer and the Checkpoint security scanner on staged files only. Catching problems locally means the central repo never sees broken code.

Server-Side Post-Receive Hook

The post-receive hook above handles the live update, but it should also append a deploy log entry. Add this line before the checkout:

echo "$(date -Iseconds) $(git rev-parse HEAD) $(whoami)" >> /var/log/deploys.log

Now every deploy is timestamped and attributable.

Rollback & Deployment Logs

To roll back, find the last good tag (git tag --sort=-creatordate | head -5) and re-checkout:

git --work-tree=/var/www/production --git-dir=/var/repo/production.git checkout -f v1.4.1

Pair this with a database backup taken before each migration, and you have a one-command rollback path.

CI/CD Options: GitHub Actions vs GitLab CI vs Custom Scripts

GitHub Actions Workflow

GitHub Actions is the most common choice in 2026. A minimal production workflow runs tests, audits dependencies, then SSHes into the server and triggers the post-receive hook:

name: Deploy
on:
 push:
 branches: [main]
jobs:
 deploy:
 runs-on: ubuntu-latest
 steps:
 - uses: actions/checkout@v4
 - run: composer audit
 - run: php artisan checkpoint:scan --json
 - run: npm audit --audit-level=high
 - name: Trigger deploy
 run: ssh deploy@prod 'cd /var/repo/production.git && git pull origin main && hooks/post-receive'
 env:
 SSH_KEY: ${{ secrets.PROD_SSH_KEY }}

GitLab CI Pipeline

GitLab CI gives you a built-in protected environment variable store and runner tags, which simplifies the same flow. The .gitlab-ci.yml equivalent uses a deploy job with environment: production and a manual gate for confirmation.

Self-Hosted Runner

For air-gapped or compliance-heavy shops, a self-hosted runner (GitHub Actions runner on your own VM, or a GitLab runner) keeps build artifacts inside your network. The trade-off is maintenance: runners need patching, and the recent Laravel-Lang detonation analysis showed that the attack was specifically observed inside a GitHub Actions runner, so harden the runner image with tools like Harden-Runner, restrict outbound traffic, and never run untrusted composer require on shared infra.

Security Best Practices for Git-Based Deployments

Dependency Auditing (Composer audit, npm audit)

Run composer audit and npm audit --audit-level=high on every push. These commands consult the Packagist and npm vulnerability databases and fail the build on known CVEs. After the Laravel-Lang incident, also pin every dependency to a specific commit SHA in composer.lock; version ranges can resolve to a poisoned tag.

Secrets Management (Vault, .env protection)

Store production secrets in HashiCorp Vault, AWS Secrets Manager, or a managed equivalent. Inject them at boot through your CI job, never through a file committed to the repo. If you must use .env, set permissions to 0600 and own it by the deploy user.

Rate Limiting & Access Tokens

Any HTTP-triggered deploy endpoint (some teams wire a Laravel route to php artisan deploy) must sit behind authentication, IP whitelisting, and Laravel's throttle middleware. According to the original SitePoint pattern, the route is hit by visiting a URL, which is convenient and dangerous in equal measure. A signed, time-limited token in the request header beats basic auth every time.

Performance & Trade-offs: Git vs Traditional SSH

Dimension Git-based Deploy Plain SSH (rsync/scp)
Deployment speed Fast for incremental pushes; first pull is slow Fast for large binary blobs
Rollback capability One command, atomic Manual file restore from backup
Audit trail Full Git log + signed commits None unless you build it
Security risks Supply-chain attacks via dependencies, tag rewrites Credential exposure, no integrity check
Setup complexity Medium (hook + bare repo) Low

Git wins on auditability and rollback. Plain SSH wins on raw transfer speed for binary-heavy releases. Most teams in 2026 run a hybrid: Git for code, rsync for large media assets that don't belong in the repo.

Common Pitfalls & Troubleshooting

Permission Errors

The most common deploy failure is Permission denied on storage/ or bootstrap/cache/. Fix it with:

sudo chown -R deploy:www-data /var/www/production
sudo chmod -R 775 storage bootstrap/cache

Never run the deploy as root; the hook should execute as the deploy user with group access to the web user.

Composer Autoload Issues

If classes suddenly disappear after a deploy, the optimized autoloader is stale. Run composer dump-autoload -o manually and check that composer.lock was committed. After the Laravel-Lang attack, also verify that no autoload.files entries point at unfamiliar paths; an unexpected src/helpers.php is a red flag.

Hook Failures

A hook that exits non-zero will leave the working tree in a half-deployed state. Add set -e at the top of the script to abort on first error, and wrap the checkout in a try/finally that restores the previous commit if anything downstream fails.

Who Should Use Git Deployment?

Target Persona Recommended Option Key Reason & Real-World Benefit
Small team (1-5 devs) GitHub Actions + post-receive hook on a $6 VPS Lowest setup cost, full audit trail, one-command rollback without paying for enterprise CI
Enterprise project GitLab CI with self-hosted runner + Vault + Harden-Runner Air-gapped builds, signed commits enforced, secrets never touch the runner disk
Open source maintainer Tagged releases + GitHub Actions with manual approval gate Community contributions stay auditable, release tags give users a trusted rollback point
Hybrid (legacy + modern apps) Git for new services, rsync for legacy monoliths Modernizes incrementally without rewriting deploy scripts for systems that aren't worth the risk

Security Tooling Spotlight: Laravel Checkpoint

Checkpoint is a development dependency that runs 26 security checks via php artisan checkpoint:scan. It supports PHP 8.1+ and Laravel 8 through 13, auto-discovers its service provider, and emits machine-readable JSON for CI gating. Install it with composer require --dev andreapollastri/checkpoint, publish the config with php artisan vendor:publish --tag=checkpoint-config, and wire the scan into your pipeline with php artisan checkpoint:github or php artisan checkpoint:gitlab. The --only and --skip flags let you focus on what matters (SQL injection, CSRF, mass-assignment, SSRF, debug functions) and suppress noise on PHP-only projects by skipping the NPM CVE audit.

Frequently Asked Questions

Use middleware to require authentication, limit to specific IPs, and add rate limiting. Store the route token in an environment variable and rotate it regularly.

No comments yet. Be the first to share your technical feedback!

Leave Technical Feedback / Discussion

B

Brieflyn Editorial Team

Senior cybersecurity researchers, DevOps engineers, and technical editors at Brieflyn.

EXPERTISE: CYBERSECURITY, CLOUD INFRASTRUCTURE, & SOFTWARE SYSTEMS
Tags: #Git deployment #Laravel deployment #Laravel GitHub Actions #Laravel GitLab CI #Laravel SSH facade #Laravel artisan commands #Composer dependency management #Composer Audit #Composer.lock pinning #Composer autoload.files #Laravel Checkpoint #Laravel security scans #Laravel CSRF protection #Laravel Mass Assignment #Laravel environment variables #Laravel .env security #Laravel migration rollback #Laravel deployment rollback #Laravel deployment best practices #Laravel deployment security #Laravel deployment route protection #Laravel deployment authentication #Laravel deployment rate limiting #Laravel deployment IP whitelisting #Laravel deployment CI/CD #Laravel deployment pipelines #Laravel deployment automation #Laravel deployment monitoring #Laravel deployment rollback strategy #Laravel deployment backups #Laravel deployment testing #Laravel deployment staging #Laravel deployment staging environment #Laravel deployment production #Laravel deployment server setup #Laravel deployment SSH key management #Laravel deployment Git tags #Laravel deployment tag audit #Laravel deployment hardening #Laravel deployment Harden-Runner #Laravel deployment GitHub Actions runner hardening #Laravel deployment GitLab CI runner hardening #Laravel deployment security best practices #Laravel deployment supply chain attack mitigation #Laravel deployment dependency audit #Laravel deployment vulnerability scanning #Laravel deployment security tooling #Laravel deployment security checklist #Laravel deployment audit logs #Laravel deployment monitoring alerts

Related Guides & Documentation