Kualo / docs
On this page

How to integrate Redis into Magento

Once Redis is running in cPanel, you can wire it into Magento 2 as session storage, default cache, or full-page cache for faster performance.

5 min read Updated 11 Jun 2026

This article assumes you have already set up Redis in cPanel. Once Redis is running, you can wire it into Magento 2 as session storage, default cache, or full-page cache.

Magento 2 uses file storage for caching by default. Redis is faster because it indexes tags in memory rather than scanning every cache file on disk. Metadata and cache records are also stored together, which means fewer inodes and fewer file operations overall.

We recommend using Redis for session storage and the default cache on every Magento store.

For full-page caching, it depends on your plan: if you are on a Kualo Magento Hosting plan, use LiteMage as your page cache - it caches at the web server level and is significantly faster. Only configure Redis as your page cache if you do not have access to LiteMage.

Always back up app/etc/env.php before editing it. Download a copy to your local computer, or duplicate the file on the server as env.php-backup. If anything goes wrong, restoring that backup puts everything back as it was.

What is a session?

A session holds user-specific data on the server for each visitor. The server links a visitor to their session using a cookie, so when someone returns to your store a few days later and their cart still contains the items they added - that is sessions at work.

How quickly data can be written to and read from session storage, how volatile it is, and how it behaves in a clustered environment all matter when choosing a storage backend. Redis handles all three well.

Use Redis for session storage

One thing to know before you start: changing where sessions are stored logs out everyone currently browsing the store, including you. Logged-in customers' carts are safe because they persist in the database, but guest carts in progress will be lost. Pick a quiet time to make the switch.

Add the following block to app/etc/env.php:

'session' =>
array (
  'save' => 'redis',
  'redis' =>
  array (
    'host' => '/home/USER/.kxcache/redis.sock',
    'port' => '0',
    'password' => '',
    'timeout' => '2.5',
    'persistent_identifier' => '',
    'database' => '2',
    'compression_threshold' => '2048',
    'compression_library' => 'gzip',
    'log_level' => '1',
    'max_concurrency' => '6',
    'break_after_frontend' => '5',
    'break_after_adminhtml' => '30',
    'first_lifetime' => '600',
    'bot_first_lifetime' => '60',
    'bot_lifetime' => '7200',
    'disable_locking' => '0',
    'min_lifetime' => '60',
    'max_lifetime' => '2592000'
  )
),

Replace USER with your cPanel username. The values to confirm for your account are:

  • host - the Redis socket address shown in cPanel under Redis.
  • port - always 0 when using a Unix socket.
  • database - a unique Redis database number for this application (see note below).

You can have up to 16 Redis databases per hosting account. If you run multiple sites or applications in the same account, each one must use a different database number to avoid data loss.

Use Redis for the default cache

The default cache holds Magento's configuration, layouts and block data, and it is read on every request that reaches Magento - including the cart, checkout and admin, which can never be served by a page cache. Moving it to Redis benefits every store, whether or not you use LiteMage.

Add the following block to app/etc/env.php:

'cache' =>
array(
  'frontend' =>
  array(
    'default' =>
    array(
      'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
      'backend_options' =>
      array(
        'server' => '/home/USER/.kxcache/redis.sock',
        'database' => '3',
        'port' => '0'
      ),
    )
  )
),

Again, replace USER with your cPanel username and confirm the host, port, and database values as described above. Note that the default cache uses its own database number (3 in the example), separate from your session storage database, so that flushing one never wipes the other.

If you are on a Kualo Magento Hosting plan with LiteMage handling your page cache, this is everything you need - skip the next section.

Use Redis for full-page caching (only without LiteMage)

If you do not have access to LiteMage, you can use Redis for Magento's full-page cache as well. Use this version of the cache block instead of the one above, which adds a page_cache entry alongside default:

'cache' =>
array(
  'frontend' =>
  array(
    'default' =>
    array(
      'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
      'backend_options' =>
      array(
        'server' => '/home/USER/.kxcache/redis.sock',
        'database' => '3',
        'port' => '0'
      ),
    ),
    'page_cache' =>
    array(
      'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
      'backend_options' =>
      array(
        'server' => '/home/USER/.kxcache/redis.sock',
        'port' => '0',
        'database' => '4',
        'compress_data' => '0'
      )
    )
  )
),

The default cache and page cache use different database numbers (3 and 4 in the example) - keep them separate from each other and from your session storage database.

Check it is working

After saving env.php, flush the cache:

php bin/magento cache:flush

Then browse the storefront, add something to the cart, and log in to the admin. If pages load normally and you stay logged in as you click around, Redis is doing its job. If the site instead shows an error about connecting to Redis, a connection detail is wrong - restore your env.php backup to get straight back to a working state, then double-check the socket path and database numbers against cPanel.

A note on flushing

Day to day, nothing changes: php bin/magento cache:flush clears the cache exactly as before. Avoid running Redis commands like FLUSHALL directly, as that wipes every database in your Redis instance at once - sessions included, which logs every customer out.

Viewing stats and monitoring Redis

Once Redis is integrated with Magento, you may want to keep an eye on how it is performing. The Redis cPanel plugin shows you live usage statistics including memory consumption and the number of connected clients, and gives you a clear view of your cache hit rate so you can see how effectively Redis is serving your store.

For more detailed inspection - such as checking which keys are stored, monitoring commands in real time, or flushing individual databases - you can use redis-cli over SSH. Our guide to monitoring Redis with redis-cli walks you through the most useful commands.

Was this helpful?
Your feedback helps us find gaps in the docs.
Still need a hand?
Real people, around the clock - start a chat or open a ticket and we'll help you put it right.