Fatal error: Class 'Redis' not found

后端 未结 3 2020
终归单人心
终归单人心 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.

提交回复
热议问题