Shopware sessions with Redis

By default, PHP saves all session information on the file system. If the store has a high number of accesses, this behavior can lead to performance problems. The Linux-based in-memory service Redis provides a remedy here.

Preparation in Shopware

First, a Redis server must be made available for the server. This can either be set up locally on the app server or externally, e.g. via an accelerator server. You can find more information about our accelerator servers here:

To integrate the session handler, the setting can either be made directly via the PHP runtime configuration or via the settings in Shopware.

Solution 1) Configuration via the Shopware server

By default, Shopware uses the standard driver for PHP sessions so that this can be easily customized via the PHP settings. To do this, log in to the relevant server via Plesk and call up the store's PHP settings.

Enter the following values in the "Additional instructions" area:

session.save_handler = redis
session.save_path = "tcp://"

If the Redis service is to be addressed via an accelerator server, use the VPC network address of the corresponding server for this purpose

Once the settings have been saved, the PHP service restarts automatically so that all PHP sessions are now controlled via the Redis server.

Attention: This adjustment will terminate all active sessions, so that customers who are already logged in will have to log in again.

Solution 2) Configuration via the Shopware environment configuration

Create a new configuration file under the path: config/packages/session.yaml. This configuration file can be used to configure the session. Then add the following content to the file:

        handler_id: "redis://%env(REDIS_HOST)%:%env(REDIS_PORT)%/%env(REDIS_DB_SESSION)%"

The following environment variables are used in this configuration file:

Variable Description
REDIS_HOST Host name or IP address for the Redis server
REDIS_PORT TCP port for Redis connections (default: 6379)
REDIS_DB_SESSION Redis database for the sessions

The variables used here must then be added to the Shopware environment configuration .env.local. To do this, open the .env.local file in the Shopware root directory and add the following part to the existing configuration:

# .env.local

# [...]

# Session Configuration

Then save the file and clear the Shopware cache via the console:

bin/console cache:clear

The Redis server is then used to manage the PHP sessions.

Shopware provides further information and adapters in the official documentation.

To the Shopware documentation →