Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel says the Predis client class cannot be found

ErrorClass "Predis\Client" not found

Short answer

Laravel is set to use Predis, but the predis/predis package is not in vendor/. Run composer require predis/predis, or composer install on the server if the package is already in composer.lock. If you would rather use the PhpRedis extension, set REDIS_CLIENT=phpredis and install the extension.

  • Applies to Laravel 12, PHP 8.4, Composer 2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether Composer knows about the package and which client the app is told to use.

    composer show predis/predis
    php artisan tinker --execute="echo config('database.redis.client');"
  2. 2Match what you see, then jump to its fix

    1. 1composer show says the package is not found.predis/predis was never requiredFix
    2. 2composer show predis/predis works on your laptop, but the error appears only on the server or in a container.The package is in composer.lock but the server's vendor folder is oldFix
    3. 3The app was working with PhpRedis, or the config says predis while you only installed the extension.REDIS_CLIENT points at a client you did not installFix

What does the error look like?

  • Class "Predis\Client" not found

Cause 1 of 3

predis/predis was never required

1Check

Laravel defaults to the PhpRedis extension. Predis is the package you add when the extension cannot be installed.

composer show predis/predis

2Fix

Require the package, which also writes it to composer.json and composer.lock.

composer require predis/predis

3Verify

The class now loads.

php artisan tinker --execute="echo get_class(new Predis\Client());"

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

The package is in composer.lock but the server's vendor folder is old

1Check

A deploy that copies code without running Composer leaves vendor/ out of date. Composer installs the exact versions from composer.lock when you run install.

ls vendor/predis

2Fix

Run Composer on the target machine as part of the deploy.

composer install --no-dev

3Verify

The folder exists and the app boots.

ls vendor/predis
php -r "require 'vendor/autoload.php'; echo class_exists('Predis\\Client') ? 'ok' : 'missing';"

Confirmed by getcomposer.org

Did this fix it?

Cause 3 of 3

REDIS_CLIENT points at a client you did not install

1Check

Laravel reads the client from the redis.client config value, which comes from REDIS_CLIENT and defaults to phpredis. After config:cache, a changed .env is ignored.

grep REDIS_CLIENT .env

2Fix

Set the variable to the client you have, then clear the cached config.

# .env
REDIS_CLIENT=predis

php artisan config:clear

3Verify

A Redis call from tinker works.

php artisan tinker --execute="Illuminate\Support\Facades\Redis::set('ping', 'pong'); echo Illuminate\Support\Facades\Redis::get('ping');"

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Commit composer.lock and run composer install in every deploy.
  • Pick one Redis client per environment and put REDIS_CLIENT in the environment file explicitly.
  • Run php artisan config:cache only after the .env is final.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.