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:
- Log in to cPanel
- Open Select PHP Version (sometimes called PHP Selector)
- Switch to the Extensions tab
- Check the redis extension
- 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
0in 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
0because 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!
