logicexception:请确保安装并启用了php redis扩展

m528fe3b  于 2021-06-09  发布在  Redis
关注(0)|答案(9)|浏览(707)

laravel版本:7.5.0 php版本:7.2数据库驱动程序版本:redis
一切正常,但突然这个错误出现,我改变了phpredis到predis,但错误是一样的。
复制步骤:我正在调用事件函数 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}

biswetbf

biswetbf1#

我总是在安装时遇到麻烦 php7.x-dev 这样地

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.

所以我跳过了 php7.x-dev 安装并直接转到 sudo pecl install redis 然后我又犯了一个错误:

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

我最后搜索安装 phpize 解决方法是安装 php-dev .
因为你们中有和我一样的问题。而不是 sudo apt-get install php7.x-dev 使用 sudo aptitude install php7.x-dev ###安装智能

sudo apt-get update
sudo apt-get install aptitude

那就跑吧 sudo apt-install php7.x-dev 如果提示,则询问是否要将以下程序包保留为当前版本:
选择“否”将自动降级或升级版本以便安装 php7.x-dev .
下一步安装redis:

sudo pecl install --force redis

注意:–force标志可确保添加扩展,而不考虑任何可能阻止安装的缓存设置。
那你应该加上 "extension=redis.so" 到php.ini。在我的例子中,php.ini位于 /etc/php/7.3/apache2/php.ini 并通过运行以下命令重新启动apache2:

sudo service apache2 restart

如果您没有安装 php-fpm 运行此命令。

sudo apt install php7.3-fpm

注意:您需要重新启动 php artisan serve . 这是因为即使您成功安装了软件包(redis,php dev),laravel也不会识别php redis,所以请记住重新启动php artisan服务。

vngu2lb8

vngu2lb82#

缺少php redis扩展。
有两种方法:
安装php redis扩展(答案https://stackoverflow.com/a/61325340/3578207)
将驱动程序更改为predis( REDIS_CLIENT 安装predis composer包( composer require predis/predis ).
但是 predis 稍微慢一点 phpredis .
p、 s.:(对于1号通道):安装phpredis扩展后,需要将此添加到 composer.json 进入 require 截面组件 "ext-redis": "*" 正确部署。请参阅about composer platform requirements。

ix0qys7i

ix0qys7i3#

如果您使用的是laravel更新版~8,则:
您必须更改两个文件:
文件1:在/bootstrap/cache/config.php中将“phpredis”替换为“predis”

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

文件2:在/config/database.php中将“phpredis”替换为“predis”

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

我的问题就这样解决了

3npbholx

3npbholx4#

如果您安装redis时 composer require predis/predis ,您需要在中更改此行 config/database.php 文件:
发件人:

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

收件人:

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

ztigrdn85#

我有点问题,伙计,但我解决了这个问题。尝试学习(我的操作系统是linux):
第1步:安装phpredis为了安装phpredis扩展的最新版本,我们可以使用pecl。要安装pecl,您需要安装php扩展和应用程序存储库(简称pear):

sudo apt install php-pear

步骤2:然后您可能还需要安装php开发工具:

sudo apt install php-dev

第3步:然后我们想继续在这里安装这个包。为此,只需运行:

sudo pecl install redis

最后:确保通过在php.ini中添加以下行来启用新的php扩展,如果没有找到这个脚本,可以在所有 extension= ```
extension = redis.io

别忘了通过以下方式重新启动apache2服务:

sudo service apache2 restart

祝你好运伙计!
7lrncoxx

7lrncoxx6#

在我的例子中,我只是在我的ubuntu服务器上安装了php扩展

sudo apt-get install php-redis
ugmeyewa

ugmeyewa7#

以防有人无意中发现。我只需安装 php-redis 在我的基于debian的linux发行版(基本操作系统)上。

ha5z0ras

ha5z0ras8#

如果您正在使用heroku,请将此添加到您的需求中:

"ext-redis": "*",
i7uaboj4

i7uaboj49#

如果你在windows中,使用这个添加predis的依赖关系 composer require predis/predis 命令。然后像这样配置.env文件

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

我正在使用redis对我的邮件进行排队,所以我设置了 QUEUE_CONNECTION=redis 以及 REDIS_CLIENT=predis 当你在本地开发的时候,这个很好用。在生产中,它是一样的,但是有点不同

相关问题