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

45,505

Solution 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

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

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

sudo apt-get install php-redis

Solution 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

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!

Share:
45,505
UMAIR ALI
Author by

UMAIR ALI

Updated on January 11, 2022

Comments

  • UMAIR ALI
    UMAIR ALI over 2 years

    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}