Redis is an in-memory data structure store. It is used as database store, cache server. You can also use redis as message broker to configure Publish/Subscribe (PUB/SUB) messaging system. Redis is capable to store Strings, Hashes, Lists, Sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes etc. It also provides a PHP module for communication between PHP script with the Redis server. Redis is written in C programming language.
This tutorial will help to install the Redis cache server along with PHP Redis extensions on a CentOS 8 Linux machine.
Prerequisites
- CentOS 8 Linux system with shell access
- Newly installed system follow the initial server setup steps.
Step 1 – Install Redis on CentOS 8
The latest Redis versions are available under the AppStream repositories of CentOS 8. Now, You can use the DNF package manager to install the Redis server on your system. To install Redis, simply execute the following command on your system:
sudo dnf install redis
After successfully installation start Redis service and enable auto-start on system reboot.
sudo systemctl enable redis.service sudo systemctl start redis.service
Redis server is up and running on your system.
● redis.service - Redis persistent key-value database Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/redis.service.d └─limit.conf Active: active (running) since Wed 2020-03-04 10:23:56 UTC; 1min 28s ago Main PID: 19911 (redis-server) Tasks: 4 (limit: 17963) Memory: 6.6M CGroup: /system.slice/redis.service └─19911 /usr/bin/redis-server 127.0.0.1:6379 Mar 08 10:23:56 tecadmin systemd[1]: Starting Redis persistent key-value database... Mar 08 10:23:56 tecadmin systemd[1]: Started Redis persistent key-value database.
Step 2 – Install Redis PHP extension
We assume you already have PHP installed on your system. You must have PHP pear package installed on your system.
sudo dnf install php-pear php-devel
Now, execute commands to enable the Redis PHP extension on your CentOS server.
pecl install igbinary igbinary-devel redis
After that execute a command to verify Redis PHP extension is enabled:
php -m | grep redis
Redis server has been installed on your system along with the PHP extension.
Step 3 – Configure Redis as a Cache Server
Redis can be started without a configuration file using a built-in default configuration. But to make any extra parameter changes you can use its configuration file that is: /etc/redis/redis.conf. Edit the Redis configuration file in a text editor to make changes
vim /etc/redis/redis.conf
Update the following values in the Redis configuration file according to your requirement. You can increase the max memory limit as per available on your server.
maxmemory 256mb maxmemory-policy allkeys-lru
The above configuration tells Redis to remove any key using the LRU algorithm when the max memory of 256mb is reached. Save the configuration file and restart the Redis service:
Step 4 – Test Connection to Redis Server
Use redis-cli tool to verify the connection between the Redis server and redis-cli.
redis-cli 127.0.0.1:6379> ping PONG 127.0.0.1:6379>
Conclusion
You have successfully installed the Redis cache server on your CentOS 8 system. If you found the older version installed follow this tutorial.