AGENT SKILL

Laravel Cloud 应用部署与管理

deploying-to-cloud

使用 `cloud` CLI 在 Laravel Cloud 上部署和管理 Laravel 应用。适用于用户想要部署应用、发布到 Cloud、创建或管理应用、环境、数据库、缓存、对象存储、队列、域名、实例、后台进程、密钥、计算资源、定时任务或 Laravel Cloud 基础设施;或查询账单、用量或支出。触发条件包括部署、发布、Cloud 管理、环境配置、数据库配置、账单或用量查询、`cloud` CLI 以及 Laravel Cloud 部署故障排查。

适用职业SRE 工程师
License 许可
MIT
最近更新
2026-11-12
Stars
★ 6
Forks
1

01 前言 Front Matter

name
deploying-to-cloud
license
MIT
metadata
{ "author": "laravel" }
description
Deploys and manages Laravel applications on Laravel Cloud using the `cloud` CLI. Use when the user wants to deploy an app, ship to Cloud, create or manage applications, environments, databases, caches, object storage, queues, domains, instances, background processes, secrets, compute, scheduled tasks, or Laravel Cloud infrastructure; or check billing, usage, or spend. Triggers on deployment, shipping, Cloud management, environment setup, database provisioning, billing or usage queries, the `cloud` CLI, and Laravel Cloud deployment troubleshooting.

02 资源文件 1

03 SKILL.md 正文

Deploying with Laravel Cloud

Use the Laravel Cloud documentation for detailed, current feature behavior. Use the Cloud CLI for Cloud operations rather than guessing dashboard or API workflows. Install it in the project and invoke it as ./vendor/bin/cloud by default; use a globally installed cloud command only as a fallback. Commands below are written as cloud for brevity; run them as ./vendor/bin/cloud unless falling back to the global installation.

Application Setup

  • Laravel Cloud deploys from GitHub, GitLab, or Bitbucket. A new Laravel application requires PHP 8.2 or later, Laravel 9 or later, a connected Git provider, and a deployment region.
  • Cloud creates environments for applications. Use separate production, staging, and preview environments; each environment has its own compute, resources, and deployment settings.
  • Keep application compute and attached resources in the same region where possible.
  • Cloud builds a Docker image using the selected PHP version, runs the configured build and deploy commands, and switches traffic to a successful deployment with zero downtime. Push-to-deploy is enabled by default, and manual deployments and deploy hooks are also available.

Build and Deploy

  • A typical Laravel build command is composer install --no-dev && npm run build.
  • Run optimization and cache-building commands during the build, not during deployment. A typical deploy command is php artisan migrate --force.
  • Build and deploy commands have a 15-minute timeout. Deploy commands run immediately before the release becomes live, and filesystem changes made by deploy commands are not persisted.
  • Do not add php artisan queue:restart, php artisan horizon:terminate, php artisan optimize:clear, or php artisan storage:link to deploy commands. Cloud handles worker restarts and process management; deploy filesystem changes are not persistent.
  • After changing environment settings, attached resources, or linked secrets, redeploy the environment for the changes to take effect.

Configuration and Resources

  • Attached databases, caches, and object storage inject their connection variables automatically. Custom environment variables take precedence over injected values.
  • Use Secrets Manager for encrypted organization-level values shared across environments. Secret values cannot be read after creation; redeploy affected environments after creating, updating, linking, unlinking, or deleting a secret.
  • Environment filesystems are ephemeral and are not shared between replicas. Use a database or Laravel Valkey for persistent cache and sessions, and Laravel Cloud Object Storage for persistent files. Do not rely on local files surviving a deployment.

Object Storage and File Visibility

  • Laravel Cloud Object Storage is backed by Cloudflare R2. R2 applies visibility at the bucket level; a bucket cannot contain a mix of private and public objects.
  • For private files, always use Storage::disk() with no arguments, such as Storage::disk()->put(...), so Laravel uses the environment's default disk. Do not pass a disk name for private/default storage. Attach a private Cloud bucket as the environment's default disk.
  • For public files, use the named public disk: Storage::disk('public')->put(...). Attach a second Cloud bucket configured as public and give it the public disk name.
  • Applications that use both private and public files therefore need two Cloud Object Storage buckets attached to the environment: a private default bucket and a public bucket named public.
  • Do not set per-file or Flysystem visibility: 'public' configuration for Cloud Object Storage. R2 does not support per-object ACL headers and rejects those requests; select the bucket visibility when creating the bucket.
  • Private buckets are not internet-accessible, but Laravel can generate temporary public URLs with Storage::temporaryUrl(...). Public buckets expose all objects through their Cloud-provided public URL.
  • Install the S3 Flysystem adapter before using Cloud Object Storage: composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies.

Queues and Scheduling

  • Managed queues are the recommended queue option. They provision dedicated workers and autoscale based on queued work.
  • Managed queues require a supported recent Laravel version and aws/aws-sdk-php; check the current Cloud documentation before changing dependencies.
  • Enable the scheduler on an App or Worker cluster to run php artisan schedule:run every minute. When an environment has multiple replicas, use Laravel's onOneServer for tasks that must run once.
  • Only Flex compute sizes can scale to zero. Scale-to-zero environments wake for Laravel scheduled tasks and queued jobs, but long-running jobs may be interrupted when the sleep timeout is reached. Use managed queues for workloads that must not be interrupted.

Domains and Storage

  • Each environment receives a laravel.cloud domain after its first successful deployment. Cloud automatically verifies custom domains and provisions SSL after the required DNS records are configured.
  • Do not use the ephemeral filesystem for persistent uploads, generated files, cache, or session data. Use the appropriate Cloud resource instead.

Cloud CLI

Setup

composer require --dev laravel/cloud-cli
./vendor/bin/cloud auth -n

If a project-local installation is not available, install the CLI globally with composer global require laravel/cloud-cli and invoke it as cloud.

cloud auth opens a browser. If a browser is unavailable, set LARAVEL_CLOUD_TOKEN in the environment. It overrides any saved token and writes nothing to disk. To save a token instead, run cloud auth:token --add --token=<token> -n or pipe it with echo "$TOKEN" | cloud auth:token --add -n.

Commands

Commands follow a CRUD pattern: resource:list, resource:get, resource:create, resource:update, resource:delete.

Available resources: application, environment, instance, database-cluster, database, cache, bucket, domain, websocket-cluster, background-process, secret, command, deployment.

Some resources have additional commands (e.g., domain:verify, database:open, instance:sizes, cache:types, <resource>:metrics). Discover these via cloud -h.

Never hardcode command signatures. Always run cloud <command> -h to discover options at runtime.

CLI Flags

  • Always add -n to every command to prevent the CLI from hanging.
  • Never use -q or --silent; they suppress all output.

Flag combos per operation:

  • Read (:list, :get) → --json -n
  • Create (:create) → --json -n
  • Update (:update) → --json -n --force
  • Delete (:delete) → -n --force (no --json)
  • Environment variables → -n --force
  • Deploy or ship → -n with all options passed explicitly (no --json)

Deployment Workflow

Determine the task and follow the matching path:

  • First deployment: inspect cloud ship -h, then run cloud ship -n with all required values.

  • Existing application:

    cloud deploy {app_name} {environment} -n --open
    cloud deploy:monitor -n
    
  • Environment variables: cloud environment:variables -n --force

  • Secrets: echo "$VALUE" | cloud secret:create --name=NAME --json -n, then cloud environment-secret:attach

  • Provision infrastructure: cloud <resource>:create --json -n

  • Monorepo (application in a subdirectory): add --root-directory=<subdir> to cloud ship or cloud application:create.

  • Custom domain: cloud domain:create --json -n, then cloud domain:verify -n.

  • Repository defaults: cloud repo:config {application} -n sets repository-local application and organization defaults. Pass --organization=<id|name|slug> when the user has multiple organizations.

For multi-step operations, see reference/checklists.md.

  • If the user's needs are unclear, ask before running anything.

When a Command Fails

  1. Read the error output.
  2. Check the resource status with :list --json -n or :get --json -n.
  3. For authentication errors, run cloud auth -n.
  4. Fix the issue and rerun the command.
  5. If the same error occurs after one fix, stop and ask the user rather than repeating the operation.

Always run cloud deploy:monitor -n after every deploy. If it fails, inspect the deployment status and logs and show the user what went wrong before attempting a fix.

Subagent Delegation

Delegate high-output operations to subagents using the Task tool to keep the main context window small. Only the summary returns; verbose output stays in the subagent's context.

Delegate these to a subagent:

  • cloud deploy:monitor -n — deployment logs can be very long
  • cloud deployment:get --json -n — full deployment details
  • cloud <resource>:list --json -n — listing many resources produces large JSON
  • cloud <resource>:metrics --json -n — every data point is included; narrow it with --fields (e.g. --fields=period,cpuUsage.average)
  • cloud command:run — when output may be long
  • cloud usage --detailed --json -n — the payload includes details for every database, cache, bucket, websocket, and application
  • Fetching docs from https://cloud.laravel.com/docs/llms.txt via WebFetch

Keep in the main context:

  • Short commands like :create, :delete, :update — output is small
  • cloud deploy -n — you need the deployment ID immediately
  • Any command where you need the result for the next step right away

Rules

Follow these rules:

  • Flag selection — always use the documented combos above
  • Deploy sequence — deploy then monitor, never skip monitoring
  • Destructive commands — always confirm with the user first, show the command and wait for approval. This includes deleting applications, environments, databases, caches, buckets, domains, or secrets.
  • Error loop — diagnose, fix once, ask user if it fails again

Use judgment for:

  • Instance sizes, regions, cluster types — ask the user if not specified
  • Which resources to provision — based on what the user describes
  • Order of provisioning — no strict sequence required
  • How to present output — summarize, show raw, or extract fields based on context

Secrets

Secrets are encrypted values shared across the organization and attached to environments. The CLI encrypts values locally, so plaintext never reaches the API.

cloud secret:list --json -n
echo "$VALUE" | cloud secret:create --name=STRIPE_KEY --json -n
cloud environment-secret:attach {environment} {secretId} -n
cloud environment-secret:list {environment} --json -n

Pipe the value in. --value= works, but leaves the plaintext in shell history and the process list.

secret:update, secret:delete, and environment-secret:attach take secret IDs, not names — names are not unique. Read IDs from cloud secret:list --json -n.

There is no secret:get, and no way to detach a secret from a single environment. secret:delete removes it and detaches it everywhere.

Secrets need the sodium PHP extension. No other command does.

Redeploy affected environments after creating, updating, attaching, or deleting a secret.

Remote Access

Tinker (v0.2.0 or later)

Run PHP code directly in a Cloud environment:

cloud tinker {environment} --code='Your PHP code here' --timeout=60 -n
  • --code — PHP code to execute (required in non-interactive mode)
  • --timeout — maximum number of seconds to wait for output (default: 60)

The code must explicitly output results using echo, dump, or similar; expressions alone produce no output.

Always pass --code and -n to avoid interactive prompts.

Remote Commands

Run shell commands on a Cloud environment:

cloud command:run {environment} --cmd='your command here' -n
  • --cmd — the command to run (required in non-interactive mode)
  • --no-monitor — skip real-time output streaming
  • --copy-output — copy output to clipboard

Review past commands:

  • cloud command:list {environment} --json -n — list command history
  • cloud command:get {commandId} --json -n — get details and output of a specific command

Billing and Usage

View billing and usage for the current organization:

cloud usage --json -n
  • --period=current|previous|1|2|3 — Billing period (default: current; 1, 2, and 3 are one, two, and three periods back, respectively). Other values return an error.
  • --environment=<id> — filter usage to a single environment
  • --detailed — include per-application, per-resource, and per-add-on breakdowns
  • --json — machine-readable output (always pair with -n)

Common queries:

  • Current spend: cloud usage --json -n | jq '.currentSpendCents'
  • Last month's bill: cloud usage --period=previous --json -n
  • One environment, full breakdown: cloud usage --environment=<id> --detailed --json -n

All amounts are in cents. Keys are camelCase at every level (e.g., currentSpendCents, bandwidth.allowanceBytes, databases[].totalCents, applications[].totalCostCents).

Config

  1. Environment: LARAVEL_CLOUD_TOKEN — an API token, taking precedence over any saved one (empty counts as unset)
  2. Global: ~/.config/cloud/config.json — auth tokens and preferences
  3. Repo-local: .cloud/config.json — app and environment defaults (set by cloud repo:config {application} -n)
  4. CLI arguments override both config files

Pass the application to repo:config. Without it, the command must prompt and fails under -n when the organization has more than one application. Deploy commands do not need these defaults; pass the application and environment to them directly.

Using multiple organizations requires multiple stored API tokens. Commands read organization_id from .cloud/config.json to select one and fail if it is not set. Set it with cloud repo:config {application} --organization=<id|name|slug> -n.

LARAVEL_CLOUD_TOKEN holds one token, so it picks the organization on its own. Naming a different one with --organization fails rather than falling back to the token's organization.

Documentation

Laravel Cloud documentation: https://cloud.laravel.com/docs/llms.txt

When the user asks how something works or needs an explanation of a Laravel Cloud feature, fetch the docs from the URL above using WebFetch and use it to provide accurate answers.

When Stuck

Verification

  1. Confirm the target application and environment before changing or deploying anything.
  2. Check staged environment changes and required resources before deployment.
  3. Monitor every deployment to completion with cloud deploy:monitor -n.
  4. For production changes, verify the application URL, logs, queues, scheduled tasks, and relevant resource health.

04 同仓库更多 Skills

karuhun-developer
karuhun-developer/template-laravel-livewire

Laravel 测试设计与评审

testing-best-practices

Laravel 测试设计与评审。适用于选择覆盖范围、测试命名或结构安排、选择断言或测试数据、隔离依赖、测试 HTTP 或安全边界、提升测试套件性能,以及评估测试价值。Pest 和 PHPUnit 语法请使用框架指南或 search-docs 查询。

测试工程师测试与质量保障
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Tailwind CSS 界面样式开发

tailwindcss-development

当用户消息以任何形式包含 'tailwind' 时必须调用。以下情形也应调用:构建响应式网格布局(多列卡片网格、商品网格)、flex/grid 页面结构(带侧边栏的仪表盘、固定顶栏、移动端切换导航)、UI 组件样式设计(卡片、表格、导航栏、定价区块、表单、输入框、徽章)、添加暗色模式变体、修复间距或排版问题,以及 Tailwind v3/v4 相关工作。核心用途:在 HTML 模板(Blade、JSX、Vue)中编写或修复 Tailwind 工具类。以下情形跳过:后端 PHP 逻辑、数据库查询、API 路由、不含 HTML/CSS 组件的 JavaScript、CSS 文件审查、构建工具配置,以及原生 CSS。

软件开发工程师前端开发与界面实现
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Laravel Slug 与自愈 URL 开发

sluggable-development

适用场景:让 Eloquent 模型的某个字段成为 slug、为 slug 列生成迁移、切换到自愈 URL,或在路由中根据 slug 解析模型。当请求提及 slug、永久链接、spatie/laravel-sluggable 包、HasSlug 或 HasTranslatableSlug trait、#[Sluggable] 特性、SlugOptions、findBySlug、自愈 URL,或 Laravel 项目中的旧 slug 重定向时触发。内容涵盖:特性(attribute)与 trait 的选择、生成唯一 slug、配置分隔符/长度/语言/作用域/唯一性、防止 slug 被覆盖、通过 spatie/laravel-translatable 实现多语言 slug、基于 slug 列的路由模型绑定、自愈路由键、通过 SelfHealing facade 自定义 308 重定向,以及通过 config/sluggable.php 覆盖默认操作。不适用于一次性 URL 安全字符串、签名 URL,或结果不存储到模型上的 Laravel 内置 Str::slug 辅助函数。

软件开发工程师PHP/Laravel 开发
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Laravel Pulse 监控配置与卡片开发

pulse-development

处理 Laravel Pulse 的安装配置与自定义卡片开发。在以下情形触发:安装 Pulse;配置仪表盘或授权门禁(Gate);设置记录器(recorder)与过滤规则;构建自定义 Livewire 卡片;通过 Redis 摄取或采样进行优化;或用户提及 /pulse、pulse:check、pulse:work、Pulse::record(),以及应用监控相关内容。

软件开发工程师PHP/Laravel 开发
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Laravel 媒体库开发

medialibrary-development

构建并使用 spatie/laravel-medialibrary 的功能,包括将文件与 Eloquent 模型关联、定义媒体集合与转换、生成响应式图片,以及获取媒体 URL 和路径。

软件开发工程师PHP/Laravel 开发
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Livewire 组件开发

livewire-development

适用于任何涉及 Livewire 的任务或问题。当用户提及 Livewire、wire: 指令,或 wire:model、wire:click、wire:sort、islands 等 Livewire 专有概念时,调用此技能。涵盖构建新组件、调试响应式问题、实时表单验证、拖放操作、加载状态、从 Livewire 3 迁移到 4、组件格式转换(SFC/MFC/基于类)以及性能优化。不适用于非 Livewire 的响应式 UI(React、Vue、仅 Alpine、Inertia.js),也不适用于不含 Livewire 的标准 Laravel 表单。

软件开发工程师PHP/Laravel 开发
★ 6