This guide is for Laravel applications that use Statamic.
Decide where your content lives
Each deployment resets your environment’s filesystem, and each replica of your App cluster has its own filesystem. If you save an entry, global, navigation, or user to disk through the Statamic control panel in production, the next deployment erases it. Other replicas never see it. You have two options:- Edit content locally. Treat production as read-only. Your team edits content on their local machines, commits the flat files to your repository, and pushes to deploy. Your content stays in version control, and this approach works well for sites that change infrequently.
- Store content in a database. If your team edits content through the control panel in production, store it in a Laravel MySQL or Postgres database using Statamic’s Eloquent driver.
php artisan migrate --force to your environment’s deploy commands.
Store assets in object storage
Statamic writes files uploaded to an asset container to the container’s filesystem disk. To keep uploads across deployments and replicas, create a Laravel Object Storage bucket and attach it to your environment. Cloud injects the S3-compatible connection variables for the bucket’s disk automatically. Next, point your asset container at the bucket’s disk name. For example, if you named the diskassets, update your container’s YAML file:
content/assets/assets.yaml
AWS_URL from the bucket settings page into your environment variables so Statamic can generate public URLs for your assets.
Refresh the Stache on deploy
Statamic indexes your content in a cache called the Stache. If your content lives in your repository, refresh the Stache after each deployment so Statamic picks up new and changed files:Enable static caching
Statamic’s static caching serves pre-rendered pages instead of building each page on every request. Statamic offers two strategies, and the right one depends on how you scale your App cluster.Half measure
The half measure strategy stores rendered pages in your application’s cache store. Requests still reach PHP, but Statamic returns the cached response without rendering the page. When your cache store is a Cloud cache, every replica shares the same cached pages, so this strategy works with autoscaling. Set the following environment variable and deploy:Full measure
The full measure strategy writes each page as an HTML file topublic/static. When your application requires statamic/cms, Cloud detects it at deploy time and configures NGINX to serve those files directly, so requests for cached pages never reach PHP. Form submissions and live previews continue to route to your application. You don’t need to write any custom NGINX configuration.
Set the following environment variable and deploy:
Monitor your site
Once your site is live, Laravel Nightwatch shows you slow requests, exceptions, queued jobs, and cache hit rates. Use it to confirm that static caching is doing its job. You can connect Nightwatch to your environment directly from the Cloud dashboard.Frequently asked questions
Do I need Statamic Pro to deploy on Cloud? No. Statamic Solo and Pro both run on Cloud. Check Statamic’s pricing page for features, such as multiple control panel users, that require a Pro license. Why did my control panel changes disappear after a deployment? Statamic writes content saved as flat files in production to the ephemeral filesystem, and each deployment resets that filesystem. Edit content locally and commit it, or store content in a database. Why are some visitors seeing outdated pages? If you use the full measure strategy with more than one replica, only the instance that handled a content change clears its cache. Set your App cluster’s autoscaling strategy to None, or switch to the half measure strategy. Does static caching affect applications that don’t use Statamic? No. Cloud configures NGINX for static caching only when your application requiresstatamic/cms.
