Skip to content

Session Cache Configuration

Since all Magento stores on Stratus are required to use cache for session storage, Stratus provides the means of using either Redis or Memcache for caching sessions.

NOTE: All Magento stores on Stratus are required to use either Redis or Memcache (recommended) for session storage. Sessions cannot be stored in files nor in the database. See Magento Requirements for the full list of requirements.

Redis

Redis can be enabled, disabled, or flushed in the Redis > Config Cache Stratus Control panel.

Using CLI commands:

  • To view: redis-cli -h redis-session info | tail -4
  • To flush sessions: redis-cli -h redis-session -p 6380 FLUSHALL

NOTE: Sessions do NOT clear with the /usr/share/stratus/cli cache.all.clear command nor do they clear during a redeploy.

Magento 1

To configure Magento 1 for using Redis:

  1. Enable the Cm_RedisSession module.
    • Open app/etc/modules/Cm_RedisSession.xml.
    • Change "false" to "true".
    • If this file does not exist, it must be installed for the Redis module to work properly.
  2. Edit the "session" block in local.xml:
<session_save>db</session_save>
<redis_session>                     
<host>redis-session</host>          
<port>6380</port>
<password></password>          
<timeout>2.5</timeout>         
<persistent></persistent>       
<db>0</db>                      
<compression_threshold>2048</compression_threshold>f
<compression_lib>gzip</compression_lib>            
<log_level>1</log_level>             
<max_concurrency>20</max_concurrency>              
<break_after_frontend>5</break_after_frontend>    
<fail_after>10</fail_after>                        
<break_after_adminhtml>30</break_after_adminhtml>
<first_lifetime>600</first_lifetime>               
<bot_first_lifetime>60</bot_first_lifetime>       
<bot_lifetime>7200</bot_lifetime>                  
<disable_locking>1</disable_locking>              
<min_lifetime>60</min_lifetime>                    
<max_lifetime>2592000</max_lifetime>               
</redis_session>

Magento 2

There are two methods to configure Magento 2 for Redis:

  • Via SSH, run php bin/magento setup:config:set --session-save=redis --session-save-redis-host=redis-session --session-save-redis-log-level=3 --session-save-redis-db=0 --session-save-redis-port=6380

    or

  • Edit the "session" block in env.php:

php
'session' =>
array (
  'save' => 'redis',
  'redis' =>
  array (
    'host' => 'redis-session',
    'port' => '6380',
    'password' => '',
    'timeout' => '2.5',
    'persistent_identifier' => '',
    'database' => '0',
    'compression_threshold' => '2048',
    'compression_library' => 'gzip',
    'log_level' => '1',
    'max_concurrency' => '20',
    'break_after_frontend' => '5',
    'break_after_adminhtml' => '30',
    'first_lifetime' => '600',
    'bot_first_lifetime' => '60',
    'bot_lifetime' => '7200',
    'disable_locking' => '1',
    'min_lifetime' => '60',
    'max_lifetime' => '2592000'
  )
),

Memcache

As an alternative to Redis for session cache, Memcache may be used. Memcache status can be observed and the sessions flushed using the Memcache Stratus Control panel.

Magento 1

Edit your session block in local.xml to enable Memcache sessions on your Magento 1 store if using PHP 5.6:

<session_save><![CDATA[memcache]]></session_save>
<session_save_path><![CDATA[tcp://memcache:11211?persistent=0&weight=2&timeout=60&retry_interval=10]]></session_save_path>

If you are using PHP 7.0 or higher with Magento 1, use the following instead:

<session_save><![CDATA[memcached]]></session_save>
<session_save_path><![CDATA[memcache:11211?persistent=0&weight=2&timeout=60&retry_interval=10]]></session_save_path>

Magento2

Edit your "session" block in env.php to enable Memcache sessions on your Magento 2 store.

'session' =>
   array (
      'save' => 'memcache',
      'save_path' => 'tcp://memcache:11211'
),

For Magento version 2.3+, add the following under PHP > OPTIONS:

session.save_handler=memcache
session.save_path=memcache:11211