Skip to main content

Install and setup Redis for WordPress on ubuntu 20.04 with php 7.4

Installing Redis on Ubuntu

Installing Redis

sudo apt update
sudo apt install redis-server

Use following command open configuration file:

sudo vim /etc/redis/redis.conf

Change/add the following:

maxmemory 256mb
maxmemory-policy allkeys-lru

Use this command to declare an init system to manage Redis as a service, providing you with more control over its operation.

supervised systemd

Restart the server to apply change:

sudo systemctl restart redis.service

Test your redis:

sudo systemctl status redis

you will get output similar to below:

● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-06-16 00:01:41 CST; 20s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
    Process: 7321 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
   Main PID: 7332 (redis-server)
      Tasks: 4 (limit: 1126)
     Memory: 2.1M
     CGroup: /system.slice/redis-server.service
             └─7332 /usr/bin/redis-server 127.0.0.1:6379

Test that Redis is functioning correctly:

redis-cli

If everything works fine, You will get a pong response once you type a ping.

Let redis start on boot:

sudo systemctl enable redis-server

Up until now, Redis has been fully installed and should be functioning properly.

Use Redis on WordPress (Extra Step)

To make Redis can be used by WordPress, we need to install PHPRedis.

Type the following commands one by one:

sudo apt-get install php-igbinary
sudo apt-get install php-redis

Use following command to open and edit php.ini file:

sudo vim /etc/php/7.4/apache2/php.ini

and add the following somewhere in the file:extension=redis.so

Restart server to apply changes:

sudo systemctl restart apache2

 

Reference:

https://stackoverflow.com/questions/46955555/how-to-install-redis-extension-for-php-7

Leave a Reply