Statamic Guide
Statamic is a powerful flat file CMS that’s perfect for the Webslice Serverless platform, we even use it for our own website! While Statamic will work out of the box, with some minor configuration, you can achieve excellent performance and keep costs low.
This guide will walk you through our recommendations, but it does assume you have a working website already. If you’re starting fresh, check out the official Statamic documentation to get your site set up locally first.
Key Concepts
- The best performance on any hosting platform will come from static caching. Using Statamic’s static caching is strongly recommended, and will provide an excellent combination of performance and price. If you can use the full Static Site Generator, you’ll get even better results.
- Git deploys support two deploy strategies: versioned (default) deploys are atomic and create a fresh copy each time, while live uses incremental syncing where untracked files persist between deploys.
- We recommend using
/mnt/data/website/sharedfor files you want to persist between deploys, such as uploads, image cache, logs, form submissions and more. This especially important when using versioned deploys. - Webslice Serverless is dynamic in nature, so if you want to use the Statamic Control Panel to make a quick edit to a live website you can. But remember, if you’re using versioned deploys, they are atomic, so you should also push the change to git locally so it’s not lost on the next deploy.
- Webslice Serverless utilizes NFS (Network File System) storage, with our custom caching layer over the top. This makes makes it fast, but some tasks, such as locking files or writing to SQLite can impact performance.
Recommended Configuration
If you want to configure your site by hand, rather than using our handy Webslice Provider, we can walk you through our recommended changes, based on our own experience running Statamic for our very own website.
Static Caching Setup
Statamic’s static caching is your best friend on a serverless platform. It pre-generates HTML files for your pages, which means:
- Lightning-fast page loads
- Minimal PHP execution
- Lower costs (fewer invocations)
- Better performance under traffic spikes
First, enable static caching in your config/statamic/static_caching.php:
return [ 'strategy' => env('STATAMIC_STATIC_CACHING_STRATEGY', half),
'strategies' => [
'half' => [ 'driver' => 'application', 'expiry' => null, ],
'full' => [ 'driver' => 'file', 'path' => public_path('static'), 'lock_hold_length' => 0, 'warm_concurrency' => 6, ],
],];The key settings here are:
strategyprepared with an environment variable which we will set to'full'for maximum cachingdriverset to'file'which works well on serverlesswarm_concurrencyat8for efficient cache warming
Environment Variables
In the Webslice Console we recommend adding the below to the Env Vars section alongside your other variables:
STATAMIC_STATIC_CACHING_STRATEGY=fullSTATAMIC_STACHE_WATCHER=falseAPP_ENV=productionAPP_DEBUG=falseThese settings optimize Statamic for serverless deployments by enabling full static caching and disabling unnecessary tasks/workloads.
Persistent Storage Configuration
You may have some data that you don’t store in your git repository (or local site copy) that you do want to ensure persists between deploys. For those files they will need storing in the persistent /mnt/data/website/shared directory:
- /mnt/data/website/shared - forms/ Form submissions - glide-cache/ Image manipulation cache - logs/ Application logs
Setting Up Symlinks
To make these directories accessible to your Statamic application, you’ll create symlinks from your application to the shared directory. The best way to do this is in a deployment script.
Create a .webslice/build.sh file in your repository:
#!/bin/bash
# Create shared directories if they don't existmkdir -p /mnt/data/website/shared/formsmkdir -p /mnt/data/website/shared/glide-cachemkdir -p /mnt/data/website/shared/logs
# Remove existing directories/links from the buildrm -rf storage/app/formsrm -rf storage/app/gliderm -rf storage/logs
# Create symlinks to persistent storageln -sf /mnt/data/website/shared/forms storage/app/formsln -sf /mnt/data/website/shared/glide-cache storage/app/glideln -sf /mnt/data/website/shared/logs storage/logs
echo "✓ Symlinks created successfully"Make the script executable:
chmod +x .webslice/build.shThis script runs before the deployment goes live and ensures your persistent data is properly linked.
Cache Warming for Peak Performance
Cache warming is the process of pre-generating your static cache files. This is crucial because we want as many pages as possible to have their cache generated before a visitor hits the page:
The Release Script
Create a .webslice/release.sh file to warm your cache after each deployment:
#!/bin/bash
echo "Starting cache warming..."
# Clear any existing cache to ensure fresh generationphp artisan cache:clearphp artisan statamic:stache:clearphp artisan statamic:static:clear
# Warm the static cachephp artisan statamic:static:warm
echo "✓ Release complete"Make it executable:
chmod +x .webslice/release.shThis script runs after your deployment goes live.
Forms and Submissions
If you’re using Statamic’s built-in forms, you need to ensure submissions are stored in persistent storage. Since we symlinked storage/app/forms to /mnt/data/website/shared/forms in our deploy script, all form submissions will be preserved across deployments.
Image Manipulation (Glide)
Statamic uses Glide for on-the-fly image manipulation. To prevent regenerating these cached images on every deployment:
In your config/statamic/assets.php:
return [ 'image_manipulation' => [ 'driver' => 'gd', // or 'imagick' if available
'cache' => true,
'cache_path' => storage_path('app/glide'),
'presets' => [ // Your image presets ], ],];The storage/app/glide directory is symlinked to /mnt/data/website/shared/glide-cache, so transformed images persist across deployments.
Deployment Checklist
When deploying your Statamic site to Webslice Serverless, follow these steps:
-
Configure static caching in
config/statamic/static_caching.phpwith thefullstrategy -
Create deployment script at
.webslice/deploy.shto set up symlinks to/mnt/data/website/shared -
Create release script at
.webslice/release.shto warm your static cache -
Make scripts executable with
chmod +x .webslice/deploy.sh .webslice/release.sh -
Configure forms to store in persistent storage if using Statamic forms
-
Set up Glide cache in persistent storage for image transformations
-
Update .gitignore to exclude symlinked directories
-
Deploy and monitor the first deployment to ensure cache warming completes