'LogicException: Please make sure the PHP Redis extension is installed and enabled

Laravel Version: 7.5.0 PHP Version: 7.2 Database Driver & Version: Redis

Everything was working fine but suddenly this error appear i changed the phpredis to predis but error is same.

Steps To Reproduce: I am calling the event function event(new ChatsEvent($data));

LogicException: Please make sure the PHP Redis extension is installed and enabled. in /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:76
Stack trace:
#0 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Support/helpers.php(428): Illuminate\Redis\Connectors\PhpRedisConnector->Illuminate\Redis\Connectors\{closure}(Object(Illuminate\Support\Facades\Redis))
#1 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(104): tap(Object(Illuminate\Support\Facades\Redis), Object(Closure))
#2 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(27): Illuminate\Redis\Connectors\PhpRedisConnector->createClient(Array)
#3 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(31): Illuminate\Redis\Connectors\PhpRedisConnector->Illuminate\Redis\Connectors\{closure}()
#4 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(111): Illuminate\Redis\Connectors\PhpRedisConnector->connect(Array, Array)
#5 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(90): Illuminate\Redis\RedisManager->resolve('default')
#6 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php(108): Illuminate\Redis\RedisManager->connection('default')
#7 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(64): Illuminate\Broadcasting\Broadcasters\RedisBroadcaster->broadcast(Array, 'ChatsEvent', Array)
#8 [internal function]: Illuminate\Broadcasting\BroadcastEvent->handle(Object(Illuminate\Broadcasting\Broadcasters\RedisBroadcaster))
#9 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#10 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#11 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#12 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#13 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(592): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#14 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#15 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#16 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#17 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#18 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(83): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Broadcasting\BroadcastEvent), false)
#19 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#20 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#21 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(85): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#22 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(59): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Broadcasting\BroadcastEvent))
#23 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#24 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(356): Illuminate\Queue\Jobs\Job->fire()
#25 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(306): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#26 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(132): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#27 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(112): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#28 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(96): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#29 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#30 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#31 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#32 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#33 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#34 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(592): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#35 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Console/Command.php(134): Illuminate\Container\Container->call(Array)
#36 /home/user/public_html/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#37 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#38 /home/user/public_html/vendor/symfony/console/Application.php(912): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /home/user/public_html/vendor/symfony/console/Application.php(264): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 /home/user/public_html/vendor/symfony/console/Application.php(140): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#41 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#42 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#43 /home/user/public_html/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#44 {main}


Solution 1:[1]

In case you install Redis with composer require predis/predis, you need to add this line to .env file:

REDIS_CLIENT=predis

Then clear cache by run this command: php artisan optimize:clear


An additional way you can change this line in config/database.php file:

From:

'client' => env('REDIS_CLIENT', 'phpredis'),

To:

'client' => env('REDIS_CLIENT', 'predis'),

Then clear cache by run this command: php artisan optimize:clear

Solution 2:[2]

Php redis extension is missing.

There are two ways:

  1. Install php redis extension (answer https://stackoverflow.com/a/61325340/3578207)
  2. Change driver to predis (REDIS_CLIENT in .env) and install predis composer package (composer require predis/predis).

But predis little bit slower that phpredis.

P.S.: (for way number 1): After installing phpredis extension you need to add this to composer.json into require section as "ext-redis": "*" for proper deployments. See about composer platform requirements.

Solution 3:[3]

For My case I just install php extension in my ubuntu server which is in below

sudo apt-get install php-redis

Solution 4:[4]

If you're in windows add the dependency of predis using this composer require predis/predis command. Then configure your .env file like this

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

I'm using redis for queueing my mail's.So I set QUEUE_CONNECTION=redis and REDIS_CLIENT=predis.This works fine when you're developing locally .In production its same but little bit different

Solution 5:[5]

I have some problem dude, but i was solved this problem. Try and learn (My OS is Linux):

Step 1: Install PhpRedis In order to install the latest version of the PhpRedis extension, we can use pecl. To install pecl you need to install the PHP Extension and Application Repository or PEAR for short:

sudo apt install php-pear

Step 2: Then you might also have to install the PHP Dev tools:

sudo apt install php-dev

Step 3: Then we would want to go ahead and install this package here. To do that, just run:

sudo pecl install redis

Finally: Make sure that you enable the new PHP extension by adding the following line to your php.ini and if you are not finded this script, you can write this script under the list of all extension=

extension = redis.io

And don't forget to restart your apache2 service by:

sudo service apache2 restart

Good luck dude!

Solution 6:[6]

I always end up facing trouble installing php7.x-dev like this

The following packages have unmet dependencies:
 php7.3-dev : Depends: libpcre2-dev (>= 10.30) but it is not going to be installed
              Depends: libssl-dev but it is not going to be installed
              Depends: php7.3-common (= 7.3.11-0ubuntu0.19.10.6) but 7.3.20-1+ubuntu19.10.1+deb.sury.org+1 is to be installed
              Recommends: pkg-php-tools but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

So I skip php7.x-dev installation and go straight to sudo pecl install redis then I got new Error:

sh: 1: phpize: not found
ERROR: `phpize' failed

I endup searching for installing phpize and the solution is to install php-dev.

for those of you have similiar problem like me. instead of sudo apt-get install php7.x-dev use sudo aptitude install php7.x-dev

Install aptitude

sudo apt-get update
sudo apt-get install aptitude

then run sudo apt-install php7.x-dev and then if prompt ask if you want to Keep the following packages at their current version:

select NO this will auto downgrade or upgrade the version in order to install php7.x-dev.

Next step install redis:

sudo pecl install --force redis

Note: The –force flag makes sure the extension is added regardless of any cached settings that may prevent installation.

Then You should add "extension=redis.so" to php.ini. in my case php.ini is located in /etc/php/7.3/apache2/php.ini

And restart apache2 by running this command:

sudo service apache2 restart

if you have not install php-fpm run this command.

sudo apt install php7.3-fpm

Note: that you need to restart the php artisan serve. this because laravel will not recognize PHP Redis even if you are successfully installed package (redis, php-dev) so keep in mind restart the php artisan serve.

Solution 7:[7]

In case anyone stumbles upon this. I've fixed this simply by installing php-redis on my Debian-based Linux distro (elementary OS).

Solution 8:[8]

I Upgraded from Laravel 5.2 to Laravel 8

Old laravel 5.2 setting was

'redis' => [

    'cluster' => false,

    'default' => [
        'host'     => '127.0.0.1',
        'port'     => 6379,
        'database' => 0,
    ],

],

Settings for Laravel 8 working fine now

'redis' => [
        
    'client' => env('REDIS_CLIENT', 'predis'),

    'default' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => env('REDIS_DB', 0),
    ],
],

Solution 9:[9]

If you are using Heroku or another PaaS platform, there is a high chance that you need to add Redis extension to your composer requirements:

"ext-redis": "*",

Solution 10:[10]

If you are using Laravel updated version ~8 THEN:

you have to change in 2 files:

File 1: replace 'phpredis' with 'predis' in /bootstrap/cache/config.php

'redis' => 
    array (
        'client' => 'predis', //you might have 'phpredis'

File 2: replace 'phpredis' with 'predis' in /config/database.php

    'redis' => [
    'client' => env('REDIS_CLIENT', 'predis'),

My problem was solved by that

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 zlodes
Solution 3 Ziaur Rahman
Solution 4 Saddan
Solution 5 Farhan Yudhi Fatah
Solution 6 Aslam H
Solution 7 spekulatius
Solution 8 Abdul Qadir R.
Solution 9
Solution 10 Mahbub Alam