skip to Main Content

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): IlluminateRedisConnectorsPhpRedisConnector->IlluminateRedisConnectors{closure}(Object(IlluminateSupportFacadesRedis))
#1 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(104): tap(Object(IlluminateSupportFacadesRedis), Object(Closure))
#2 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(27): IlluminateRedisConnectorsPhpRedisConnector->createClient(Array)
#3 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(31): IlluminateRedisConnectorsPhpRedisConnector->IlluminateRedisConnectors{closure}()
#4 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(111): IlluminateRedisConnectorsPhpRedisConnector->connect(Array, Array)
#5 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(90): IlluminateRedisRedisManager->resolve('default')
#6 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php(108): IlluminateRedisRedisManager->connection('default')
#7 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(64): IlluminateBroadcastingBroadcastersRedisBroadcaster->broadcast(Array, 'ChatsEvent', Array)
#8 [internal function]: IlluminateBroadcastingBroadcastEvent->handle(Object(IlluminateBroadcastingBroadcastersRedisBroadcaster))
#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): IlluminateContainerBoundMethod::IlluminateContainer{closure}()
#11 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): IlluminateContainerUtil::unwrapIfClosure(Object(Closure))
#12 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): IlluminateContainerBoundMethod::callBoundMethod(Object(IlluminateFoundationApplication), Array, Object(Closure))
#13 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(592): IlluminateContainerBoundMethod::call(Object(IlluminateFoundationApplication), Array, Array, NULL)
#14 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): IlluminateContainerContainer->call(Array)
#15 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): IlluminateBusDispatcher->IlluminateBus{closure}(Object(IlluminateBroadcastingBroadcastEvent))
#16 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateBroadcastingBroadcastEvent))
#17 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): IlluminatePipelinePipeline->then(Object(Closure))
#18 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(83): IlluminateBusDispatcher->dispatchNow(Object(IlluminateBroadcastingBroadcastEvent), false)
#19 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): IlluminateQueueCallQueuedHandler->IlluminateQueue{closure}(Object(IlluminateBroadcastingBroadcastEvent))
#20 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateBroadcastingBroadcastEvent))
#21 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(85): IlluminatePipelinePipeline->then(Object(Closure))
#22 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(59): IlluminateQueueCallQueuedHandler->dispatchThroughMiddleware(Object(IlluminateQueueJobsDatabaseJob), Object(IlluminateBroadcastingBroadcastEvent))
#23 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): IlluminateQueueCallQueuedHandler->call(Object(IlluminateQueueJobsDatabaseJob), Array)
#24 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(356): IlluminateQueueJobsJob->fire()
#25 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(306): IlluminateQueueWorker->process('database', Object(IlluminateQueueJobsDatabaseJob), Object(IlluminateQueueWorkerOptions))
#26 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(132): IlluminateQueueWorker->runJob(Object(IlluminateQueueJobsDatabaseJob), 'database', Object(IlluminateQueueWorkerOptions))
#27 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(112): IlluminateQueueWorker->daemon('database', 'default', Object(IlluminateQueueWorkerOptions))
#28 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(96): IlluminateQueueConsoleWorkCommand->runWorker('database', 'default')
#29 [internal function]: IlluminateQueueConsoleWorkCommand->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): IlluminateContainerBoundMethod::IlluminateContainer{closure}()
#32 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): IlluminateContainerUtil::unwrapIfClosure(Object(Closure))
#33 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): IlluminateContainerBoundMethod::callBoundMethod(Object(IlluminateFoundationApplication), Array, Object(Closure))
#34 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(592): IlluminateContainerBoundMethod::call(Object(IlluminateFoundationApplication), Array, Array, NULL)
#35 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Console/Command.php(134): IlluminateContainerContainer->call(Array)
#36 /home/user/public_html/vendor/symfony/console/Command/Command.php(255): IlluminateConsoleCommand->execute(Object(SymfonyComponentConsoleInputArgvInput), Object(IlluminateConsoleOutputStyle))
#37 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): SymfonyComponentConsoleCommandCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(IlluminateConsoleOutputStyle))
#38 /home/user/public_html/vendor/symfony/console/Application.php(912): IlluminateConsoleCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#39 /home/user/public_html/vendor/symfony/console/Application.php(264): SymfonyComponentConsoleApplication->doRunCommand(Object(IlluminateQueueConsoleWorkCommand), Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#40 /home/user/public_html/vendor/symfony/console/Application.php(140): SymfonyComponentConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#41 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#42 /home/user/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): IlluminateConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#43 /home/user/public_html/artisan(36): IlluminateFoundationConsoleKernel->handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#44 {main}

10

Answers


  1. 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!

    Login or Signup to reply.
  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.

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
  4. 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": "*",
    
    Login or Signup to reply.
  5. 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

    Login or Signup to reply.
  6. For My case I just install php extension in my ubuntu server which is in below

    sudo apt-get install php-redis
    
    Login or Signup to reply.
  7. 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.

    Login or Signup to reply.
  8. 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

    Login or Signup to reply.
  9. I upgraded from Laravel 5.2 to Laravel 8.

    Old Laravel 5.2 settings were:

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

    Settings for Laravel 8, which are 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),
        ],
    ],
    
    Login or Signup to reply.
  10. this problem goes out after reboot of the server and nothing more, u don’t need to install or reinstall anything just reboot, that’s the secret matter

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search