Speeding Up Magento 2 with Redis on an Nginx Server

Speeding Up Magento 2 with Redis on an Nginx Server

Redis is a fast in-memory store that works well for Magento 2’s cache and sessions, taking load off the file system.

1. Install

sudo apt update
sudo apt install redis-server

2. Configure

sudo nano /etc/redis/redis.conf

Change supervised no to supervised systemd.

3. Restart and test

sudo systemctl restart redis.service
sudo systemctl status redis
redis-cli
sudo systemctl restart redis.service
sudo apt install net-tools
sudo netstat -lnp | grep redis
php bin/magento cache:flush

4. Tell Magento to use it

Update app/etc/env.php:

'cache' => [
    'frontend' => [
        'default' => [
            'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
            'backend_options' => [
                'server' => '127.0.0.1',
                'database' => '0',
                'port' => '6379'
            ],
        ],
        'page_cache' => [
            'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
            'backend_options' => [
                'server' => '127.0.0.1',
                'port' => '6379',
                'database' => '1',
                'compress_data' => '0'
            ]
        ]
    ],
    'allow_parallel_generation' => false
],

Flush the cache afterwards. Use separate Redis databases for cache, page cache and sessions.

Need a second pair of eyes on this? Our team handles Magento development every week. See how we can help.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.