Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Laravel Deployment to VPS (Nginx, PHP-FPM, Queues)

    by Saizul Amin

    1

    Zero-downtime VPS deployment suite for Laravel with atomic symlinks, Nginx, and Supervisor configs.

    $9

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Laravel Deployment to VPS (Nginx, PHP-FPM, Queues)

    Laravel Deployment to VPS (Nginx, PHP-FPM, Queues)

    Example session with this skill installed

    Run the Laravel Deployment to VPS skill on my project and give me a prioritised list of what to fix, with exact changes.

    • Read your context and instructions
    • Compiled the laravel deployment to

    Here is what the Laravel Deployment to VPS (Nginx, PHP-FPM, Queues) skill produced.

    Demo: real, unedited output of the skill's bundled script on a sample input from its test suite.

    Output

    ===== deploy.sh =====
    #!/usr/bin/env bash
    
    # Zero-downtime deploy for shop (shop.example.com).
    # Layout: shop/releases/<timestamp>, shop/shared/{.env,storage}, shop/current -> release
    # Run as deploy on the server: bash deploy.sh [git-ref]
    set -euo pipefail
    
    BASE="shop"
    REPO="git@github.com:acme/shop.git"
    REF="${1:-main}"
    KEEP=5
    PHP_FPM="php8.3-fpm"
    HEALTH_URL="${HEALTH_URL:-https://shop.example.com/up}"
    
    RELEASE="$(date -u +%Y%m%d%H%M%S)"
    RELEASE_DIR="$BASE/releases/$RELEASE"
    
    log() { printf '\n==> %s\n' "$*"; }
    
    [ -f "$BASE/shared/.env" ] || { echo "missing $BASE/shared/.env (see INSTALL.md)" >&2; exit 1; }
    mkdir -p "$BASE/releases" "$BASE/shared/storage"
    
    log "Cloning $REF into $RELEASE_DIR"
    git clone --depth 1 --branch "$REF" "$REPO" "$RELEASE_DIR"
    cd "$RELEASE_DIR"
    
    log "Linking shared .env and storage"
    rm -rf storage
    ln -s "$BASE/shared/storage" storage
    ln -s "$BASE/shared/.env" .env
    mkdir -p storage/app/public storage/framework/{cache/data,sessions,views} storage/logs bootstrap/cache
    
    log "Installing PHP dependencies"
    composer install --no-dev --optimize-autoloader --no-interaction --prefer-dist --no-progress
    
    log "Building front-end assets"
    if [ -f package-lock.json ]; then
      npm ci --no-audit --no-fund
      npm run build
      rm -rf node_modules
    fi
    
    log "Running migrations"
    php artisan migrate --force
    
    log "Caching config, routes, events and views"
    php artisan optimize
    php artisan view:cache
    php artisan storage:link --force >/dev/null 2>&1 || true
    
    log "Switching current -> $RELEASE (atomic)"
    ln -sfn "$RELEASE_DIR" "$BASE/current.tmp"
    mv -Tf "$BASE/current.tmp" "$BASE/current"
    
    log "Reloading PHP-FPM (clears OPcache) and restarting queue workers"
    sudo /usr/bin/systemctl reload "$PHP_FPM"
    cd "$BASE/current"
    php artisan queue:restart
    
    log "Health check $HEALTH_URL"
    if ! curl -fsS --max-time 10 -o /dev/null "$HEALTH_URL"; then
      echo "health check failed: run rollback.sh to return to the previous release" >&2
      exit 1
    fi
    
    log "Removing old releases (keeping $KEEP)"
    find "$BASE/releases" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort | head -n -"$KEEP" | while read -r old; do
      [ "$old" = "$RELEASE" ] || rm -rf -- "$BASE/releases/$old"
    done
    
    log "Deployed $REF as $RELEASE"
    
    ===== rollback.sh =====
    #!/usr/bin/env bash
    
    # Point shop/current at the previous release. Database migrations are NOT rolled back.
    set -euo pipefail
    
    BASE="shop"
    CURRENT="$(basename "$(readlink -f "$BASE/current")")"
    PREVIOUS="$(find "$BASE/releases" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' \
    
      | sort | grep -B1 -x "$CURRENT" | head -n 1)"
    
    
    if [ -z "$PREVIOUS" ] || [ "$PREVIOUS" = "$CURRENT" ]; then
      echo "no previous release before $CURRENT" >&2
      exit 1
    fi
    
    echo "Rolling back $CURRENT -> $PREVIOUS"
    ln -sfn "$BASE/releases/$PREVIOUS" "$BASE/current.tmp"
    mv -Tf "$BASE/current.tmp" "$BASE/current"
    sudo /usr/bin/systemctl reload "php8.3-fpm"
    cd "$BASE/current"
    php artisan optimize
    php artisan queue:restart
    echo "Now serving $PREVIOUS"
    
    ===== nginx-shop.conf =====
    
    # /etc/nginx/sites-available/shop.conf
    # HTTPS is added by certbot (--nginx) or by your own ssl_certificate lines.
    server {
        listen 80;
        listen [::]:80;
        server_name shop.example.com;
        root shop/current/public;
    
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header Referrer-Policy "strict-origin-when-cross-origin" always;
    
        index index.php;
        charset utf-8;
        client_max_body_size 20m;
        server_tokens off;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }
    
        # Vite builds hashed file names: cache them for a year
        location /build/ {
            expires 1y;
            add_header Cache-Control "public, immutable";
            access_log off;
            try_files $uri =404;
        }
    
        error_page 404 /index.php;
    
        location ~ ^/index\.php(/|$) {
            fastcgi_pass unix:/run/php/php8.3-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            # $realpath_root resolves the `current` symlink so OPcache sees the new release
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            fastcgi_hide_header X-Powered-By;
            fastcgi_read_timeout 60s;
        }
    
        # Only index.php is executable; deny dotfiles except .well-known (ACME)
    

    What you do next

    1. Fix the highest-severity items first.
    2. Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
    3. Keep the skill installed and re-run it whenever the project changes.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Stop losing traffic to 500 errors during deployments or struggling with stale code after a git pull. This skill generates a battle-tested, zero-downtime deployment pipeline for Laravel applications on standard Ubuntu or Debian servers.

    What it does

    • Atomic deployments via a releases/shared/current symlink structure to prevent partial updates.
    • Automated build pipeline including Composer optimization, Vite asset builds, and database migrations.
    • System configuration generating optimized Nginx blocks, Supervisor worker configs, and Cron entries.
    • OPcache management with PHP-FPM reloads and Horizon/Queue restarts to ensure new code runs immediately.
    • Instant rollbacks via a dedicated script that switches the symlink back to the previous stable release.

    How it works

    1. Fact gathering where the agent identifies your PHP version, repository details, and queue driver requirements.
    2. File generation to create the deploy.sh, rollback.sh, and necessary Linux service configurations locally.
    3. Server provisioning following the generated INSTALL.md to set up the directory structure and permissions.
    4. Execution of the deploy script which clones, builds, and switches the live symlink only after a successful health check.

    Frameworks & tools

    Targeted at Laravel 10 through 12. Compatible with Ubuntu 22.04/24.04 and Debian 12. Supports Nginx, PHP-FPM 8.2+, Composer, Vite, and Supervisor for queue management.

    Why this beats prompting it yourself

    Generic prompts often miss the critical $realpath_root setting in Nginx or the specific sudoers rules needed for non-root deployments. This skill enforces a specific directory layout that prevents OPcache stale code issues and ensures migrations run safely before the traffic switch.

    Use cases

    • Migrating a Laravel app from shared hosting to a dedicated DigitalOcean or Hetzner VPS.
    • Replacing unstable git pull deployment methods with a professional release-based workflow.
    • Setting up Horizon or queue workers with automatic restarts on every new code push.
    • Establishing a reliable rollback mechanism for production environments.

    Known limitations

    Does not handle initial server hardening like firewalls or SSH keys. Designed for single-server setups rather than multi-node clusters behind a load balancer.


    Open source: saizul/laravel-php-skills on GitHub (MIT licence, by Saizul Amin).

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

    Requires pre-configured SSH access and basic server hardening. Not designed for containerized or multi-server load-balanced environments.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Frequently Asked Questions

    The skill implements an atomic symlink strategy (current/releases/shared) similar to tools like Envoyer or Capistrano, ensuring your site stays online and error-free while new code is being built.

    This skill is optimized for Laravel 10, 11, and 12 running on Ubuntu 22.04/24.04 or Debian 12 with PHP-FPM 8.2+.

    You receive a complete deployment suite including custom deploy/rollback scripts, optimized Nginx server blocks, Supervisor worker configurations, and a step-by-step installation guide.

    Yes, the skill generates specific Supervisor configurations and deployment hooks to automatically restart Horizon or your queue workers so they always run the latest code.

    This skill is designed for single-server VPS environments; while it provides a professional pipeline, it does not support multi-server load balancing or container orchestration like Kubernetes.

    Unlike generic prompts, this skill enforces critical production settings like $realpath_root for Nginx and proper sudoers permissions that prevent common OPcache and permission issues.

    New in APIs & Backend