- Home
- Skills
- APIs & Backend
- Laravel Deployment to VPS (Nginx, PHP-FPM, Queues)
Works with the AI Agents you already use
Laravel Deployment to VPS (Nginx, PHP-FPM, Queues)
by Saizul Amin
Zero-downtime VPS deployment suite for Laravel with atomic symlinks, Nginx, and Supervisor configs.
$9
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
- Fix the highest-severity items first.
- Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
- 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
- Fact gathering where the agent identifies your PHP version, repository details, and queue driver requirements.
- File generation to create the
deploy.sh,rollback.sh, and necessary Linux service configurations locally. - Server provisioning following the generated
INSTALL.mdto set up the directory structure and permissions. - 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 pulldeployment 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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.
Trust & safety
Security scan
Security scan passed 1 day ago
- Software
Python 3.8+
Git
Permissions
Allowed Hosts