Installing phpredis on Ubuntu 14.04 for PHP 7.1

13,213

Solution 1

May you just need to install this using a ppa package like:

sudo apt-get install php7.1-redis

Solution 2

Ok so I noticed that phpinfo showed

PHP API 20160303

which means that the earlier error makes sense. The PHP version of the web server is 7.1, however, when running the phpredis phpize it shows the one for 7.2.

So I just made sure to remove php7.2-dev and re-install php7.1 via apt-get, then re-run the github repo steps above.

Share:
13,213
MW Millar
Author by

MW Millar

Updated on June 22, 2022

Comments

  • MW Millar
    MW Millar almost 2 years

    My php -v

    PHP 7.1.15-1+ubuntu14.04.1+deb.sury.org+2 (cli) (built: Mar 6 2018 11:51:39) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans with Zend OPcache v7.1.15-1+ubuntu14.04.1+deb.sury.org+2, Copyright (c) 1999-2018, by Zend Technologies

    I have tried both the pecl way

    sudo pecl install redis
    sudo service php7.1-fpm restart
    

    And the manual way from https://github.com/phpredis/phpredis

    phpize
    ./configure [--enable-redis-igbinary]
    make && make install
    

    I made sure to put

    extension=/usr/lib/php/20170718/redis.so
    

    into the php.ini file as shown when I run echo phpinfo();

    e.g.

    /etc/php/7.1/cli/php.ini
    

    When I run the inbuilt web server I get

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20170718/redis.so' - /usr/lib/php/20170718/redis.so: undefined symbol: zend_empty_string in Unknown on line 0

    Strangely PHPStorm autocompletes the PHP Redis class, so

    $redis = new \Redis();
    $redis->connect('127.0.0.1', 6379);
    

    I can click into the Redis class and see it is the correct one.

    I wonder if it is a version difference? Maybe because I am using 32-bit?

    Another strange thing is, if I just put

    extension=redis.so 
    

    in php.ini, it seems to be looking for an older build

    PHP Startup: Unable to load dynamic library '/usr/lib/php/20160303/redis.so' - /usr/lib/php/20160303/redis.so: cannot open shared object file: No such file or directory in Unknown on line 0

    When I run

    sudo apt-get install php-redis
    

    it installs and means that no start up error shows, but the web page still shows a

    Class 'Redis' not found

    One other thing I notice is that in Apache, there is no error, and the class is found. But when I run php's inbuilt web server, the not found error shows up.

  • MW Millar
    MW Millar about 6 years
    Cheers for the answer, that is important, but I needed to remove 7.2 first.
  • Akram Chauhan
    Akram Chauhan over 2 years
    For beginners, you can change php7.1 with your php version.