Fatal error: Class 'Redis' not found

后端 未结 3 2007
终归单人心
终归单人心 2021-02-18 23:36

I\'ve installed Redis on my ubuntu 14 server with phpredis extension. Im using Nginx server. I have php testing script

$redis=new Redis() or die(\"Cannot load Re         


        
相关标签:
3条回答
  • 2021-02-18 23:43

    TLDR;
    On Ubuntu 16.04 using NGINX with PHP 7 I found that PHP-FPM was not restarted. A simple restart of the service worked for me:

    sudo service php-fpm restart
    OR
    sudo service php7.0-fpm restart
    OR
    sudo service php5-fpm restart

    You may need to need to search "restart PHP-FPM" in case any of the above commands don't work for you.

    To give some context, I had installed phpredis using the standard sudo apt-get install php-redis and I restarted nginx using sudo systemctl restart nginx but whenever trying to use new Redis() in PHP I received the same error as in the question (... Class 'Redis' not found...).

    When running phpinfo(); in a PHP file on the NGINX server I could see the PHP-FPM was loading additional configuration from /etc/php/7.0/fpm/conf.d ("Scan this dir for additional .ini files" section). Looking in that directory with a simple ls -al /etc/php/7.0/fpm/conf.d I can see there is a symlink named 20-redis.ini but that file was not being loaded in the phpinfo section "Additional .ini files parsed".

    The problem as I see it now is that restarting NGINX did not restart PHP-FPM. Using ps aux | grep php-fpm to see if there were any PHP-FPM processes running when I had stopped NGINX confirmed my suspicions. Because a restart is required to reload the PHP modules the PHP-FPM restart was required in addition to the NGINX restart.

    0 讨论(0)
  • 2021-02-18 23:46

    Manual instalation of PhpRedis solved this problem

    git clone git://github.com/nicolasff/phpredis.git
    cd phpredis
    phpize
    ./configure
    make
    sudo -s make install
    
    sudo -s
    echo "extension=redis.so">/etc/php5/conf.d/redis.ini
    ln -s /etc/php5/conf.d/redis.ini /etc/php5/fpm/conf.d/20-redis.ini
    exit
    

    copied from Rico's Tech Memo

    0 讨论(0)
  • 2021-02-18 23:48

    You have installed redis but not php-redis. you can simply run the command below to install php-redis

    sudo apt-get install php-redis
    
    0 讨论(0)
提交回复
热议问题