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. Any entry, global, navigation, or user that is saved to disk through the Statamic control panel in production will be lost on the next deployment and will not be visible to other replicas. 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. This keeps your content in version control and 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
Files uploaded to a Statamic asset container are written 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 new and changed files are picked up: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 cached pages are returned without reaching 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 gives you visibility into slow requests, exceptions, queued jobs, and cache hit rates, which is useful for confirming 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? Content saved as flat files in production is written to the ephemeral filesystem and reset on each deployment. 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 only configures NGINX for static caching when your application requiresstatamic/cms.
