PHP Redis Session Handler – WordPress Redis
Redis is an open source key-value cache and storage system, also referred to as a data structure server for its advanced support for several data types, such as hashes, lists, sets, and bitmaps, amongst others. It also supports clustering, which makes it often used for highly-available and scalable environments.
In this tutorial, we’ll see how to install and configure an external Redis server to be used as a session handler for a PHP application running on CentOS 8.
The session handler is responsible for storing and retrieving data saved into sessions – by default, PHP uses files for that. An external session handler can be used for creating scalable PHP environments behind a load balancer, where all application nodes will connect to a central server to share session information.
How to Set Up a Redis Server as a Session Handler:
# nano /usr/local/php74/lib/php.ini
# session.save_handler = redis
# session.save_path = "tcp://127.0.0.1:6379?auth=secretpass123"
Redis Extra Security:
Set a Password for the Redis Server
To add an extra layer of security to your Redis installation, you are encouraged to set a password for accessing the server data. We will edit the same configuration file from the previous step,
sudo nano /etc/redis/redis.conf
Now, uncomment the line that contains
requirepass, and set a strong password:/etc/redis/redis.conf
Restart the Redis service so the changes take effect:
sudo service redis-server restart
PHP, Redis, Session, Wordpress