Redis is an efficient object caching application. If you have a Wordpress site based on Litespeed (OpenLitespeed) server and you have LSCache installed, you can further speed up your site with an object cache.

However, you can only choose to install one of the object cache programs, Redis and Memcached. For Litespeed/Wordpress systems, there is not much difference in performance between the two as object cache programs. Today we will cover how to install a Redis server.

1. System environment

The operating system for this article is Ubuntu 20.04 LTS 64 bit, and the server operating environment is OpenLitespeed server with LSPHP 7.4.

The installation steps for other versions are similar.

2. Installing the Redis server

We can install the Redis server directly from the package manager. Execute the following command.

1
2
apt-get update && apt-get upgrade -y
apt-get install redis -y

If you are using the CentOS series, the command to install the Redis server is as follows.

1
2
3
yum update -y
yum install epel-release -y
yum install redis -y

3. compile and install php-redis extension

Redis is much easier to install than Memcached, mainly because its PHP extensions are easier to install.

First, install the necessary compilation environment.

1
apt-get install build-essential zlib1g-dev libexpat1-dev openssl libssl-dev libsasl2-dev libpcre3-dev -y

Then get the php-redis source code from pecl:

1
2
3
wget https://pecl.php.net/get/redis -O redis.tgz
tar xvf redis.tgz
cd redis-*

Before you start compiling, you first need to pre-process the source code with phpize. Normally, OpenLitespeed does not pre-install phpize and we need to install the lsphp74-dev package additionally.

1
2
apt-get install lsphp74-dev -y
/usr/local/lsws/lsphp74/bin/phpize7.4

Now you can start compiling.

1
2
3
./configure --with-php-config=/usr/local/lsws/lsphp74/bin/php-config7.4
make
make install

When you make install, you will be prompted for the installation path of the php-redis extension, as shown below.

php-redis extension

For example, here I have /usr/local/lsws/lsphp74/lib/php/20190902/redis.so

So, edit the php.ini file and write the redis expansion location to

1
echo "extension=/usr/local/lsws/lsphp74/lib/php/20190902/redis.so" >> /usr/local/lsws/lsphp74/etc/php/7.4/litespeed/php.ini

Finally, restart OpenLitespeed:

1
/usr/local/lsws/bin/lswsctrl restart

4. check php-redis installation

After installing the Redis server with the php-redis extension, we should be able to see the corresponding Redis block in phpinfo(), as follows.

php-redis

In SSH, we can also test if the Redis server is running properly. Execute.

1
redis-cli ping

If Redis is running properly, you can see the following response.

1
PONG

5. Enable Redis object caching for WordPress

After installation, we can use the object cache by enabling the redis function in LSCache.

redis-lscache-w

As shown above. If Redis is installed correctly, the Redis Extension and Connection Test values should both be green.

To sum up, we installed Redis server and lsphp-redis extension on Ubuntu 20.04 LTS operating system, and used Redis object cache and LSCache to speed up WordPress.


Reference https://qing.su/article/install-redis-for-litespeed.html