Craft CMS reference
Reference for running Craft CMS on TurboStack: how to point Craft's cache and sessions at the platform's Redis, and how to run the background queue. For setup see Deploy Craft CMS; for tuning see Craft CMS best practices.
File layout
Your Craft codebase lives under your system user's home directory. ~ is that home directory (for example /var/www/prod/).
For ownership and permissions, see Application file layout and permissions.
Redis cache and sessions
TurboStack provisions Redis, but Craft only uses it once you point its cache and session components at it in config/app.php. Install the Redis driver first:
composer require yiisoft/yii2-redis
Then configure the components. This uses the cache instance for the data cache and the persistent instance for sessions, each on its own database index:
<?php
use craft\helpers\App;
return [
'components' => [
// Connection to the Redis cache instance (unix socket)
'redis' => [
'class' => yii\redis\Connection::class,
'unixSocket' => '/var/run/redis/redis.sock',
'database' => 0,
],
'cache' => [
'class' => yii\redis\Cache::class,
'defaultDuration' => 86400,
'keyPrefix' => 'craft',
],
// Sessions on the persistent instance, with its own database index
'session' => function() {
return Craft::createObject([
'class' => yii\redis\Session::class,
'as session' => craft\behaviors\SessionBehavior::class,
'redis' => [
'class' => yii\redis\Connection::class,
'unixSocket' => '/var/run/redis-persistent/redis.sock',
'database' => 1,
],
]);
},
],
];
unixSocketreplaceshostnameandport; leave those out, because they are ignored when a socket path is set.- Give each component its own
databaseindex. Craft warns that sharing an index lets one component flush another's data. - The
sessioncomponent may also live inconfig/app.web.php, which Craft loads only for web requests. Either file works.
Note
The two instances are the cache on /var/run/redis/redis.sock and the persistent instance on /var/run/redis-persistent/redis.sock. See How to inspect Redis with Redis Insight for the instance and database layout.
Background queue
Craft processes long tasks (image transforms, search indexing, emails) through a queue. By default it runs the queue on web requests, which adds load to PHP. On a busy site, turn that off and run the queue as a persistent worker instead.
Disable the web-triggered runner in config/general.php:
'runQueueAutomatically' => false,
Then run Craft's queue as a user system service so it restarts on failure and survives logout. Keep the number of workers within the host's processor budget (see Scale throughput with more instances).
Related
- Deploy Craft CMS
- Craft CMS best practices
- Troubleshooting Craft CMS
- Application file layout and permissions
- How to manage user system services