Englishen
Your cart: 0
Cart Subtotal: €0.00

How to enable Redis in Magento 2

Redis is a powerful in-memory data storage tool that drastically speeds up your Magento store by redirecting sessions and cache from a slower database or file system to fast RAM.

In this post, we will look at how to find information about your Redis server and how to properly integrate it into Magento.

1. How to enable Redis in a cPanel environment (shared hosting)

On shared servers, Redis typically does not operate via the classic TCP port 6379, but through a Unix socket enabled by the hosting provider. Before connecting Redis to Magento, you must check if PHP support for Redis is active at all.

Activating the Redis extension in cPanel

In most cPanel environments (especially on CloudLinux servers), you enable Redis through the PHP selector:

  1. Log in to cPanel
  2. Open Select PHP Version (sometimes called PHP Selector)
  3. Switch to the Extensions tab
  4. Check the redis extension
  5. Save the changes

This activates the PHP extension phpredis, which allows Magento to connect to the Redis server.

If this extension is not enabled, Magento will report a connection error when trying to use the Redis backend, or the cache will not initialize at all.

Note:
If you use the NEOSERV Turbo LiteSpeed package, Redis is available in cPanel at no extra charge (via Unix socket). You can activate it directly in the hosting settings.

2. How to find information for Redis?

Before starting the configuration, you need to know where Redis is running. It usually runs on certain ports (port 6379) or via a Unix socket, which is common on shared hosting.

Searching for the process via console

The easiest way to find this information is by using the command ps:

ps aux | grep redis

Look for something similar in the output:

  • redis-server *:6379 (means it runs on port 6379)
  • redis-server unixsocket:/home/user/.tmp/redis.sock (means it uses a Unix socket)

Checking the connection

Once you have the information, you can check if you can connect:

For port:

redis-cli -p 6379 ping

For Unix socket:

redis-cli -s /path/to/redis.sock ping

If you get a response PONG, everything is working!

3. Complete configuration for app/etc/env.php

Below is the complete code to insert into your file.

A. Session configuration

Sessions are critical as they refresh with every user click.

'session' => [
'save' => 'redis',
'redis' => [
'host' => '/home/username/.cagefs/tmp/redis.sock', // Path to socket or IP
'port' => '0', // 0 for socket, 6379 for port
'password' => '', // Password if set
'timeout' => '2.5', // Connection timeout (seconds)
'persistent_identifier' => '', // ID for persistent connection
'database' => '2', // Database number (recommended 2)
'compression_threshold' => '2048', // Compress data over 2KB
'compression_library' => 'gzip', // Compression library (gzip or lzf)
'log_level' => '1', // 1 for errors, 4 for all
'max_concurrency' => '6', // Max concurrent processes per session
'break_after_frontend' => '5', // Time to release lock (seconds)
'break_after_adminhtml' => '30', // Time for admin lock
'first_lifetime' => '600', // New session lifetime
'bot_first_lifetime' => '60', // Time for bots
'bot_lifetime' => '7200', // Total time for bots
'disable_locking' => '0', // 0 enables locking (safer)
'min_lifetime' => '60', // Minimum session time
'max_lifetime' => '2592000', // Maximum time (30 days)
'sentinel_master' => '', // For Redis Sentinel clusters
'sentinel_servers' => '',
'sentinel_connect_retries' => '5',
'sentinel_verify_master' => '0'
]
],

Explanation of key fields:

  • database: Redis allows multiple separate databases (usually 0-15). We use database 2 for sessions to avoid mixing with cache.
  • compression_threshold: Magento will compress data before sending it to Redis if it is larger than this value. This saves memory.
  • max_concurrency: Prevents one user from consuming too many resources (e.g., if they open 10 tabs at once).
  • disable_locking: Always set to 0 in production to prevent session data corruption.

B. Cache configuration

This covers the default cache and full page cache (Page Cache).

'cache' => [
'frontend' => [
'default' => [
'id_prefix' => '2e4_',
'backend' => 'Magento\Framework\Cache\Backend\Redis',
'backend_options' => [
'server' => '/home/username/.cagefs/tmp/redis.sock',
'port' => '0',
'password' => '',
'database' => '0', // Database 0 for default cache
'compress_data' => '1', // Enable compression
'compression_lib' => 'gzip'
]
],
'page_cache' => [
'id_prefix' => '2e4_',
'backend' => 'Magento\Framework\Cache\Backend\Redis',
'backend_options' => [
'server' => '/home/username/.cagefs/tmp/redis.sock',
'port' => '0',
'password' => '',
'database' => '1', // Database 1 for FPC
'compress_data' => '0', // FPC is usually not compressed for max speed
'compression_lib' => 'gzip'
]
]
]
],

Explanation of key fields:

  • id_prefix: A short code (e.g., 2e4_) added to each key. This is necessary if you have multiple stores on the same Redis server.
  • backend: Tells Magento to use the Redis driver.
  • database: Database 0 is for general Magento data, and database 1 is for Full Page Cache (FPC).
  • compress_data: For FPC, it is often set to 0 because the data is already in HTML form and it is faster for Redis to return it directly without unpacking.

3. Conclusion

After editing the file, be sure to clear the cache:

php bin/magento cache:flush

With Redis, your store will breathe easier, and the processor will be less burdened with MySQL queries for sessions!

Stop browsing. Start selling. Contact me now at anze@degriz.net.

Access Premium Content for Free

Subscribe to our newsletter and get free access to premium content. Discover valuable insights and exclusive resources available only to our subscribers.

Privacy Policy: Newsletter Subscription

By entering your email address, you are subscribing to the newsletter, through which Degriz will inform you about new online and in-store offerings, marketing activities, and other promotions.

By subscribing to the newsletter, you are also enrolled in the benefits database that Degriz offers to its users.

For the newsletter subscription, Degriz d.o.o. collects the following information: email address, IP address, and if you subscribe as a registered member, your name, surname, address, and phone number.

After submitting the form with your email address, you will receive a confirmation message at the specified address – by confirming this, you will be subscribed to the Degriz newsletter until you unsubscribe (so-called opt-in approval). You can request, in writing or by clicking the Unsubscribe button in the newsletter, that the data controller permanently or temporarily stops using your personal data for direct marketing purposes. Your request will be fulfilled within 15 days of receiving it, as prescribed by law. You can also request the transfer or access to your data.

Degriz d.o.o. is committed to protecting your data in accordance with the legislation governing personal data protection.

The sender of the newsletter and controller of your personal data is: Degriz, d.o.o., Gorica pri Šmartnem 45a, 3000 Celje, SI 67287743

Check out the full Privacy Policy

Newsletter

My name is Anže, and I am a Magento certified expert in solutions and a creator of multiple award-winning online stores.

I am the architect behind all Degriz projects. You will surely come across me if we collaborate. Even though the phone keeps ringing, you can always tap me on the shoulder if you need advice regarding online stores and their functioning.

I specialize in building custom online stores and I am a master of unique techniques to enhance conversion on your website.

© 2010 - 2026 Degriz. All rights reserved. Built with love on Magento.
Partial use of the content is permitted with mandatory attribution. The content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0) or under our own license.