跳到正文
DEV Community· Andrea Pollastri·· 2 小時前AI 評分43

如何使用 Cipi 免費零停機部署 Laravel 至自有 VPS

Deploy Laravel to your own VPS with zero downtime, for free (with Cipi)

AI 導讀

Cipi 是免費、採用 MIT 授權的開源工具,可在 Ubuntu VPS 上管理 Laravel 應用,支援 Git 零停機部署、HTTPS、佇列、排程、備份及安全更新。文章示範如何由空白 VPS 部署 Laravel 應用,並設定推送程式碼時自動部署;亦可使用 cipi.yml 管理伺服器設定。

正文

Deploying Laravel usually goes one of two ways. You pay every month for a hosted panel that manages your servers, or you spend a weekend with Nginx configs, PHP-FPM pools, Supervisor files, certbot and a deploy script that one day takes the site down mid-release.

There's a third way. Cipi is a free, open-source (MIT) tool that you install on the server itself. One command turns a fresh Ubuntu VPS into a platform for many Laravel apps: zero-downtime deploys from Git, queues, the scheduler, HTTPS, backups and security patches. There's no subscription and no external control plane. If you want a dashboard, there's an optional self-hosted one.

In this post we'll go from an empty VPS to a live Laravel app on HTTPS that deploys on every git push.

What you need

  • A VPS with Ubuntu 24.04 or 26.04 LTS and a public IPv4: Hetzner, DigitalOcean, AWS, Vultr, OVHcloud and others all work. 2 GB of RAM is comfortable for a couple of apps.
  • A domain whose DNS you can edit.
  • Your Laravel app in a Git repository (GitHub, GitLab, Bitbucket, Gitea, Azure DevOps…).
  • An SSH key on your laptop (ssh-keygen -t ed25519 if you don't have one). Point your domain's A record at the server's IP now, so DNS propagates while you install.

1. Install Cipi (one command)

ssh root@203.0.113.10
wget -O - https://cipi.sh/setup.sh | bash

The installer asks for your public SSH key, shows what it's about to do, and then sets up:

  • Nginx, PHP (several versions side by side), MariaDB, Valkey (the open-source Redis), Supervisor, Node and Certbot
  • a firewall with only ports 22, 80 and 443 open, Fail2ban, key-only SSH with root login disabled
  • automatic security updates, plus nightly PHP patching It takes about ten minutes. Save the credentials it prints at the end: they're shown once.

From now on you log in as the cipi admin user:

ssh cipi@203.0.113.10
sudo cipi status

2. Create the app

sudo cipi app create --user=shop --domain=shop.example.com \
    --repository=git@github.com:acme/shop.git --branch=main --php=8.5

That one command creates an isolated app:

You get Where
A Linux user shop apps can't read each other's files
A database and database user shop MariaDB (or PostgreSQL with --engine=pgsql)
A PHP-FPM pool on the PHP version you chose each app picks its own
An Nginx vhost for the domain
A queue worker under Supervisor ready for your jobs
The Laravel scheduler, every minute already in the app user's crontab
A .env with every credential filled in /home/shop/shared/.env
A read-only deploy key and a signed webhook for Git

Running sudo cipi app create with no flags starts a wizard instead.

3. Connect the repository

The summary shows a deploy key. Add it to your repository as a read-only deploy key (GitHub: Settings → Deploy keys). If you save a Git provider token in Cipi, it adds the key and the push webhook for you. Check that the server can read the repo:

sudo cipi git check shop

4. Deploy, with zero downtime

sudo cipi deploy shop

Here's what a deploy does, and why visitors never see a broken site:

  1. The repository is cloned into a new folder, releases/<timestamp>. The live site keeps running.
  2. composer install --no-dev runs with the app's own PHP version.
  3. .env and storage/ are linked from shared/, so they survive every deploy and rollback.
  4. Migrations and artisan optimize run inside the new release.
  5. The current symlink switches to the new release in one atomic step.
  6. Queue workers restart on the new code. If any step fails, nothing switches: the old release keeps serving. Something wrong after a deploy? Go back instantly:
sudo cipi deploy shop --rollback

Front-end assets? Add a build command and Vite runs before the switch:

sudo cipi app deploy-config shop --node-build='npm ci && npm run build'

5. HTTPS

sudo cipi ssl install shop

A free Let's Encrypt certificate covers the domain and its aliases, renews by itself, and APP_URL switches to https://. Behind Cloudflare's proxy, or for wildcard domains like *.yourapp.com, issue it over DNS instead with sudo cipi ssl install shop --dns=cloudflare.

6. Deploy on every push

The webhook was created with the app, so pushing to main now deploys. If you'd rather deploy only when tests pass, turn the webhook off and deploy from CI:

# .github/workflows/deploy.yml (excerpt)
- uses: appleboy/ssh-action@v1
  with:
    host: ${{ secrets.SERVER_HOST }}
    username: cipi
    key: ${{ secrets.CI_SSH_KEY }}
    script: sudo cipi deploy shop || (sudo cipi deploy shop --rollback && exit 1)

Add a health check, and a broken release rolls itself back:

sudo cipi health set shop --url=https://shop.example.com/up --expect=200
sudo cipi deploy shop --rollback-on-unhealthy

7. Queues, Horizon, Octane, Reverb

Production Laravel needs more than PHP-FPM. With Cipi each of these is one command:

sudo cipi worker add shop --queue=emails --processes=3   # another queue
sudo cipi worker horizon enable shop                     # or hand everything to Horizon
sudo cipi app convert shop --to=octane                   # Octane on FrankenPHP
sudo cipi app reverb enable shop                         # WebSockets on the same domain

8. Keep server settings in Git with cipi.yml

This is the part I like most. Instead of remembering which commands you ran six months ago, you describe the app in a file next to composer.json:

version: 1

app:
  php: "8.5"
  aliases: ["www.shop.example.com"]

workers:
  queues:
    - { queue: default, processes: 2 }
    - { queue: emails, processes: 3, tries: 5 }

schedule: true

health:
  url: "https://shop.example.com/up"
  rollback_on_unhealthy: true

deploy:
  predeploy_snapshot: true
  node_build: "npm ci && npm run build"

backup:
  profiles:
    - { name: shop-nightly, scope: all, cron: "0 2 * * *", keep_days: 14, destinations: [s3], encrypt: true }

Changes go through a pull request like any other code. On the server, cipi yml plan shop shows exactly what would change, and cipi yml apply shop applies it all or nothing. Already have an app? sudo cipi yml generate shop > cipi.yml writes the file from its current setup, so the first plan changes nothing.

There are 18 ready-made recipes: a SaaS with Horizon and Reverb, an Octane API, an online shop, a multi-tenant app, staging, Next.js and more.

9. Backups you can actually restore

sudo cipi backup configure            # an S3-compatible bucket
sudo cipi backup profile add shop-db --scope=db --databases=shop \
    --every=30m --keep=48 --dest=s3 --encrypt
sudo cipi backup verify

Archives are encrypted on the server before they leave it, and Cipi warns you when a backup is overdue.

What else is in the box

  • Security: one isolated user per app, nightly PHP patches with alerts while a vulnerable build is installed, optional CrowdSec, malware integrity scans, secrets encrypted at rest, and Cloudflare Zero Trust that can close every port.
  • Optional web panel: self-hosted, for one or many servers, with roles, 2FA and SSO. See cipi.sh/web-panel.
  • REST API, PHP SDK and cipi-cli to drive servers from your laptop or CI.
  • MCP for AI assistants: Claude, Cursor or VS Code can read logs, check migrations and deploy, behind SQL and Artisan guards with secret redaction. See cipi.sh/mcp.
  • Anonymized database dumps: production data for developers, without the personal data. ## How it compares
Cipi Hosted server panels
Price Free (MIT) A monthly plan, on top of the server
Where it runs On your server A third-party SaaS
Server settings in Git cipi.yml In a dashboard
Creates servers on cloud accounts No: you create the VPS Usually yes

Hosted panels are great if you want servers created for you from a dashboard and a support contract. If you'd rather own the whole stack and stop paying for the control plane, Cipi does the job. There are 22 honest comparisons (Forge, Ploi, Laravel Cloud, Coolify, cPanel…), each with a step-by-step migration.

Try it

wget -O - https://cipi.sh/setup.sh | bash

來源:DEV Community · dev.to