How to Install PHP Redis on PHP-FPM

To install PHP Redis, use the following instructions:

 

Step 1

Install PHP Redis on Ubuntu with the following command and hit ENTER on every prompt without typing anything:

 

sudo pecl install redis

 

If you get an error you may need to install the PHP XML extension

 

sudo apt-get install php7.2-xml

 

If you get a phpize error install PHP-dev then run the PHP Redis install command again:

 

sudo apt-get install php7.2-dev

 

Step 2

Restart the PHP service to apply the changes (replace the PHP version number with yours:)

 

sudo systemctl restart php7.2-fpm.service

 

Now check redis is active with:

 

php -m

 

If you don't see redis try adding redis.ini manually:

 

Create a redis.ini file in the mods-available directory for your PHP version:

 

sudo nano /etc/php/7.2/mods-available/redis.ini

 

Add the following content to the file and save:

 

/etc/php/7.2/mods-available/redis.ini
extension=redis.so

 

Then use the commands below to create symlinks manually:

 

sudo ln -sf /etc/php/7.2/mods-available/redis.ini /etc/php/7.2/fpm/conf.d/20-redis.ini
sudo ln -sf /etc/php/7.2/mods-available/redis.ini /etc/php/7.2/cli/conf.d/20-redis.ini
sudo systemctl restart php7.2-fpm.service
redis