简体   繁体   English

如何为 php 安装 redis 扩展 7

[英]How to install redis extension for php 7

Referred this link https://anton.logvinenko.name/en/blog/how-to-install-redis-and-redis-php-client.html参考此链接https://anton.logvinenko.name/en/blog/how-to-install-redis-and-redis-php-client.html

And done following steps并完成以下步骤

PhpRedis for PHP 7 (Skip it if you have different PHP version) PhpRedis for PHP 7(PHP版本不同的可以跳过)

Install required package安装需要 package

apt-get install php7.0-dev

Download PhpRedis下载 PhpRedis

cd /tmp
wget https://github.com/phpredis/phpredis/archive/php7.zip -O phpredis.zip

But, https://github.com/phpredis/phpredis/archive/php7.zip file not found for installation.但是,找不到要安装的https://github.com/phpredis/phpredis/archive/php7.zip文件。

Yesterday, I installed Redis on my Vagrant box ( /etc/php/7.0 ):昨天,我在我的 Vagrant 盒子( /etc/php/7.0 )上安装了 Redis:

  • sudo pecl install redis
  • sudo service php7.0-fpm restart

(optional: run php -m for listing the php modules). (可选:运行php -m以列出 php 模块)。

Now, you can use the Redis class in your php code.现在,您可以在 php 代码中使用Redis类。

Try to use this url https://github.com/phpredis/phpredis/archive/5.2.2.zip尝试使用这个网址https://github.com/phpredis/phpredis/archive/5.2.2.zip

wget https://github.com/phpredis/phpredis/archive/5.2.2.zip -O phpredis.zip

Or use this command:或者使用这个命令:

sudo apt-get install php-redis

I found a repository from ubuntu:我从 ubuntu 找到了一个存储库

sudo apt-get install php-redis
  • Restart apache after installation.安装后重启apache。

I just ran the command below for Cent os 7我刚刚为 Cent os 7 运行了以下命令

yum install php-redis

Resolved my issue and i added the config in php.ini manualy解决了我的问题,我在 php.ini 中手动添加了配置

You should add "extension=redis.so" to php.ini您应该将“extension=redis.so”添加到 php.ini

For people who are using MAMP, you want to execute the pecl installer from withing MAMP.对于使用 MAMP 的人,您希望通过 MAMP 执行 pecl 安装程序。 This follows the installment from https://github.com/phpredis/phpredis/blob/develop/INSTALL.markdown .这是https://github.com/phpredis/phpredis/blob/develop/INSTALL.markdown的分期付款。

/Applications/MAMP/bin/php/php7.3.9/bin/pecl install redis

Change the php version to yours.将 php 版本更改为您的版本。

After successfully installing, will probably say something like this:安装成功后,大概会说这样的话:

configuration option "php_ini" is not set to php.ini location
You should add "extension=redis.so" to php.ini

So you need to go to your php.ini, and add extension=redis.so .所以你需要去你的 php.ini,并添加extension=redis.so

For me, this folder is: /Applications/MAMP/bin/php/php7.3.9/conf/php.ini对我来说,这个文件夹是: /Applications/MAMP/bin/php/php7.3.9/conf/php.ini

After restarting your MAMP, you will see a redis module on this page (ports might not be the same): http://localhost:8888/MAMP/index.php?language=English&page=phpinfo重启你的 MAMP 后,你会在这个页面上看到一个 redis 模块(端口可能不一样): http://localhost:8888/MAMP/index.php?language=English&page=phpinfo

If you happen to be in a docker container just:如果您碰巧在 docker 容器中:

pecl install redis
docker-php-ext-enable redis

will do in most cases.大多数情况下都可以。

Install redis with a command:使用命令安装 redis:

sudo apt-get install php7.0-redis

This GitHub is a great resource for MAMP users.这个 GitHub 是 MAMP 用户的一个很好的资源。

For Mac Users:对于 Mac 用户:

  1. Download redis.so from the appropriate subdirectory of the repo based on major and minor version number XY ( following semver ).根据主要和次要版本号 XY(在 semver 之后)从repo的相应子目录下载redis.so
  2. Move the file to /Applications/MAMP/bin/php/phpX.YX/lib/php/extensions/no-debug-non-zts-xxxxxxxx将文件移动到/Applications/MAMP/bin/php/phpX.YX/lib/php/extensions/no-debug-non-zts-xxxxxxxx
  3. Add extension=redis.so to the end of php.ini在 php.ini 末尾添加extension=redis.so

Updated resource above, previously listed this上面更新了资源,之前列出了这个

For Debian-based Linux distros you need a php-dev and pkg-php-tools packages for building native PHP extension from phpredis source code:对于基于 Debian 的 Linux 发行版,您需要一个php-devpkg-php-tools包来从phpredis源代码构建原生 PHP 扩展:

sudo apt update
sudo apt install php-dev pkg-php-tools --yes
sudo pecl channel-update pecl.php.net
sudo pecl install redis

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM