Statamic Documentation
website·Indexed 35 days ago
https://statamic.dev/modifiers/A self-hosted PHP application built as a Laravel package. Documentation covers installation via CLI, Docker, Laravel Herd, and various cloud providers, as well as core concepts, licensing for Core and Pro editions, configuration, and upgrade guides for versions v2 through v6.
What's inside Statamic
- Statamic is a 'bring your own HTML' platform. It does not provide a default design, CSS, or JavaScript. Developers are responsible for providing the frontend layer, though Starter Kits can be used to accelerate the process. This makes Statamic a tool for building custom sites rather than a 'no-code' solution for assembly, although the resulting site is easily maintainable by non-developers via the Control Panel.
Understand Statamic's 'Flat-First' data architecture
Statamic operates in flat file mode by default, meaning content, configurations, and templates are stored as files. This enables end-to-end version control, the ability to manage the site directly in a code editor, and simplified deployment. While Statamic supports relational databases (MySQL, Postgres) or NoSQL solutions (MongoDB, Redis) via its Repositories feature, these should typically only be used when scaling for tens of thousands of records or extremely high traffic.Migrate Statamic v2 themes and views to v3
v2-to-v3.mdThe concept of 'themes' has been removed in v3. The site now has a single frontend located in theresourcesdirectory. Templates (views) are now consolidated inresources/viewsinstead of being split acrosstemplates,layouts, andpartialsdirectories.Retrieve environment variables in config and views
Use theenv()helper function within PHP config files to retrieve environment variables. You can provide a second argument as a default value. Once a variable is mapped in a config file, it can be accessed in views using the{{ config }}tag (Antlers) or theconfig()helper (Blade).// In config/app.php 'awesome' => env('ENABLE_AWESOME', true),{{ config:app:awesome }}{{ config('app.awesome') }}Manage Statamic data storage in existing Laravel apps
By default, when installed into an existing Laravel application, Statamic stores content as flat files.
- Database Content: To store content in a database instead of files, refer to the "Storing Content in a Database" guide.
- Database Users: To keep users in a database, refer to the "Storing Users in a Database in an Existing Laravel App" guide.
After installation, the following directories are added to the project:
content/resources/users/config/statamic/
Install Statamic using the CLI
The recommended way to install Statamic is via the CLI installer. This requires a local development environment with Composer installed. After installing the CLI globally, you can create a new site project using thestatamic newcommand.# Install the Statamic CLI globally composer global require statamic/cli # Create a new site project statamic new cyberspace-placeEnable and verify Nginx site configuration
Test the Nginx configuration for syntax errors, create a symlink to thesites-enableddirectory, and reload the Nginx service to apply changes.# Test configuration sudo nginx -t # Enable site and reload sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ sudo systemctl reload nginxConfigure Nginx to serve a Statamic site
Install Nginx and create a site configuration file in/etc/nginx/sites-available/. Ensure thefastcgi_passdirective matches the version of PHP-FPM installed on your system (e.g.,php8.3-fpm.sock).server { listen 80; server_name example.com; root /var/www/html/example.com/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; set $try_location @static; if ($request_method != GET) { set $try_location @not_static; } if ($args ~* "live-preview=(.*)") { set $try_location @not_static; } location / { try_files $uri $try_location; } location @static { try_files /static${uri}_$args.html $uri $uri/ /index.php?$args; } location @not_static { try_files $uri /index.php?$args; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } }Set up a local development environment for Statamic
Depending on your operating system, use the following recommended tools to develop Statamic locally:
- macOS and Windows: Use Laravel Herd, which provides a native environment including
php,composer, andnpm. - Linux: Manually install
php,composer, andnpm. Users on Ubuntu or Debian-based systems are encouraged to follow a dedicated Ubuntu installation guide.
- macOS and Windows: Use Laravel Herd, which provides a native environment including
Design a flexible content schema in Statamic
Statamic does not enforce a specific content model. Developers can define their own field names, organize entries into custom collections, and create taxonomies with specific URL patterns.
Common strategies include:
- The 'One Big Field' approach: Using the
Bardfieldtype to combine content and markup in a single area, potentially adding custom Set blocks. - The 'Discrete Field' approach: Breaking content into small, optional fields and using conditional fields to show or hide them based on logic.
- The 'One Big Field' approach: Using the
Configure a Pages collection manually in Statamic
When installing Statamic into an existing Laravel app, no content is included. To set up a standard 'Pages' collection for a home page and tree-structured pages, you can either copy the
pages.yamlandpagesdirectory from the Statamic GitHub repository or configure it via the Control Panel:- Create a collection named
pages. - Set the route to
{parent_uri}/{slug}. - Enable the "Orderable" toggle.
- Enable the "Expect a root page" toggle.
- Create the first entry to serve as the home page.
- Create a collection named
Install Statamic via the CLI
Statamic can be installed on macOS, Windows, or Linux provided you have PHP 8.3+ (with required extensions) and Composer installed. The Statamic CLI provides a setup wizard for starter kits, initial user creation, and git initialization.# Install the Statamic CLI globally composer global require statamic/cli # Verify installation statamic list