skip to Main Content

I’m getting spammed with Please make sure the PHP Redis extension is installed and enabled. in my logs, despite having the redis.so extension installed on MacOS. I installed the Redis extension by running pecl install redis, which succeeds with the following message:

Installing '/usr/local/Cellar/php/7.3.12/pecl/20180731/redis.so'
install ok: channel://pecl.php.net/redis-5.1.1
Extension redis enabled in php.ini

By running phpinfo() in tinker, I can see that my loaded php.ini is

Configuration File (php.ini) Path => /usr/local/etc/php/7.3
Loaded Configuration File => /usr/local/etc/php/7.3/php.ini

If I open up /usr/local/etc/php/7.3/php.ini, extension="redis.so" is listed at the top of the file.

What makes this more and more strange is that if I dig deeper into where the original Please make sure the PHP Redis extension is installed and enabled. error is coming from, it looks to be in laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:76, which looks like this:

throw new LogicException(extension_loaded('redis') ? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'  : 'Please make sure the PHP Redis extension is installed and enabled.');

So according to this, the extension isn’t loaded. But if I load up tinker again and run extension_loaded('redis') then I get a true result.

I can’t for the life of me figure out what’s going on here. Why does PhpRedisConnector not see that the extension is loaded?

For completeness, I’ve also removed the Redis alias from my app.php file as instructed to by the Laravel docs.

3

Answers


  1. For those who installed Redis with composer require predis/predis, as described in the Laravel official documentation.

    In config/database.php, change:

    'redis' => [
    
        //'client' => env('REDIS_CLIENT', 'phpredis'),
        'client' => env('REDIS_CLIENT', 'predis'),
    
    Login or Signup to reply.
  2. Add this to your env file

    REDIS_HOST=127.0.0.1
    REDIS_PASSWORD=null
    REDIS_PORT=6379
    REDIS_CLIENT=predis     <---Add this line-->
    
    Login or Signup to reply.
  3. The accepted answer is just a workaround to use predis instead of PHPRedis. If you still want to use PHPRedis and still facing the same issue as the main question then maybe you are running into the same issue as me. In my case the Please make sure the PHP Redis extension is installed and enabled error only throw out if running the Job by crontab. Turn out that somehow the version of PHP which using in the crontab is not the same as the PHP version that I installed the PHP Redis to. So here is what I did:

    • Find out where is the current PHP path:
        MacBook-Pro:hpt hantran$ which php
        /usr/local/bin/php
    
    • Change the crontab from
    * * * * * cd /Applications/XAMPP/xamppfiles/htdocs/hpt  && php artisan schedule:run >> /dev/null 2>&1
    
    • To:
    * * * * * cd /Applications/XAMPP/xamppfiles/htdocs/hpt  && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
    

    The original answer can be found here https://laracasts.com/discuss/channels/general-discussion/please-make-sure-the-php-redis-extension-is-installed-and-enabled?page=1#reply=659249

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