How do I install the PHP Redis Extension for PHP 7.2?

Linode Staff

I'm having trouble with installing the PHP Redis extension on PHP 7.2. Any suggestions or tips to help me out with this?

4 Replies

I haven't personally tried this myself but I did find a few links that may be able to assist you with getting this installed on your server.

If you are using Debian or Ubuntu, you can simply do:

apt-get install php-redis

-- sw

Hi, Thanks for your suggestions.

I have installed the PHP Redis extension for PHP 5.6 and PHP 7.2 version. The issue is that the extension does not load up for PHP 7.2 when I check phpinfo but for PHP 5.6 it shows up in phpinfo.

I have confirmed the installation by using the below command

**for php 7.2 : **
[root@li2095-109 php.d]# php72 -m |grep redis
redis

**for php 5.6 : **
[root@li2095-109 php.d]# php -m |grep redis
PHP Warning: Module 'redis' already loaded in Unknown on line 0
redis

Can you suggest the exact steps for installing it for both the PHP version correctly?

WARNING! The following assumes you are using Debian/Ubuntu.

WARNING! WARNING! WARNING! You can seriously mess up your system doing all this. I take no responsibility for your actions.

You need to make sure that PHP is loading the PHP/redis interface shared library.

  • Make sure the shared library is installed properly
stevewi@bill:~$ sudo find / -name igbinary.so
/usr/lib/php/<someversion>/igbinary.so
stevewi@bill:~$ sudo find / -name redis.so
/usr/lib/php/<someversion>/redis.so

n.b., you may have more than one…one for PHP5.6 and one for PHP7.2. They will be distinguished by <someversion>. You interpret <someversion> using the format YYYYjj.mm, where:

YYYY is a year
jj is the major revision (07)
mm is the minor revision (2x)

  • Next, you have to make sure the PHP configuration for the shared libraries exists:
stevewi@bill:~$ ls /etc/php/7.2/mods-available/redis.ini
/etc/php/7.2/mods-available/redis.ini
stevewi@bill:~$ ls /etc/php/7.2/mods-available/igbinary.ini
/etc/php/7.2/mods-available/igbinary.ini
  • If that's ok, you need to make sure the library is loaded by PHP7.2. You should have the following:
stevewi@bill:~$ cd /etc/php/7.2
stevewi@bill:/etc/php/7.2$ find . -name *igbinary* 
./cli/conf.d/20-igbinary.ini
./mods-available/igbinary.ini
./fpm/conf.d/20-igbinary.ini
stevewi@bill:/etc/php/7.2$ find . -name *redis* 
./cli/conf.d/20-redis.ini
./mods-available/redis.ini
./fpm/conf.d/20-redis.ini
  • ./cli/conf.d/20-igbinary.ini and ./fpm/conf.d/20-igbinary.ini should be symlinks to ./mods-available/igbinary.ini:
stevewi@bill:/etc/php/7.2$ ll ./cli/conf.d/20-igbinary.ini
lrwxrwxrwx 1 root root 40 <date> ./cli/conf.d/20-igbinary.ini -> /etc/php/7.2/mods-available/igbinary.ini
  • - ./cli/conf.d/20-redis.ini and ./fpm/conf.d/20-redis.ini should be symlinks to ./mods-available/redis.ini:
stevewi@bill:/etc/php/7.2$ ll ./cli/conf.d/20-redis.ini
lrwxrwxrwx 1 root root 40 <date> ./cli/conf.d/20-redis.ini -> /etc/php/7.2/mods-available/redis.ini

Most likely, the symlinks are missing. You can can establish them by

stevewi@bill:~$ cd /etc/php/7.2
stevewi@bill:/etc/php/7.2$ sudo ln -s /etc/php/7.2/mods-available/redis.ini ./cli
stevewi@bill:/etc/php/7.2$ sudo ln -s /etc/php/7.2/mods-available/redis.ini ./fpm
stevewi@bill:/etc/php/7.2$ sudo ln -s /etc/php/7.2/mods-available/igbinary.ini ./cli
stevewi@bill:/etc/php/7.2$ sudo ln -s /etc/php/7.2/mods-available/igbinary.ini ./fpm
  • If you are using php-fpm, it needs to be restarted:
stevewi@bill:/etc/php/7.2$ sudo systemctl restart php72-fpm
  • You can try your searches with the PHP cli processor again.

The install of the php-redis and php-igbinary packages should have done all this for you (php-redis is dependent on php-igbinary).

WARNING! The above assumes you are using Debian/Ubuntu.

WARNING! WARNING! WARNING! You can seriously mess up your system doing all this. I take no responsibility for your actions.

-- sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct