首页 > linux, redis > linux下php安装redis扩展

linux下php安装redis扩展

2020年9月18日 发表评论 阅读评论

php安装redis扩展,可以通过源码编译,也可以通过pecl来快速安装,本文介绍通过pecl安装redis扩展。

安装前准备:

yum -y install libzstd-devel

pecl install lzf

pecl install zstd

查看redis扩展的版本,通过 pecl search redis 可以看到redis扩展的最新版本是5.3.1

[root@67 ~]# /usr/local/php/bin/pecl search redis
Retrieving data...0%
Matched packages, channel pecl.php.net:
=======================================
Package Stable/(Latest) Local
redis 5.3.1 (stable) PHP extension for interfacing with Redis

安装redis扩展,这里我们使用php自带的pecl命令来安装php扩展 pecl install redis,会提三个是否支持,输入yes即可。

[root@67 ~]# /usr/local/php/bin/pecl install redis
downloading redis-5.3.1.tgz ...
Starting to download redis-5.3.1.tgz (264,485 bytes)
......................................................done: 264,485 bytes
29 source files, building
running: phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
enable igbinary serializer support? [no] : yes
enable lzf compression support? [no] : yes
enable zstd compression support? [no] : yes
building in /tmp/pear/temp/pear-build-rootQKHhBf/redis-5.3.1
running: /tmp/pear/temp/redis/configure --with-php-config=/usr/local/php/bin/phpd=yes
checking for grep that handles long lines and -e... /usr/bin/grep
...

Build process completed successfully
Installing '/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/redis.so'
install ok: channel://pecl.php.net/redis-5.3.1
Extension redis enabled in php.ini

出现如上内容表示安装完成。

安装问题排查:
1.找不不到igbinary.h
checking for redis json support... enabled
checking for igbinary includes... configure: error: Cannot find igbinary.h
ERROR: /tmp/pear/temp/redis/configure --with-php-config=/usr/local/php/bin/php-=yes' failed

igbinary.h 找不到,是因为我们没有安装igbinary库,我们先安装igbinary, pecl install igbinary ,重新运行后可以找到igbinary.h,进而出现如下错误

2.找不到libzstd 路径

checking for pkg-config... /usr/bin/pkg-config
checking for libzstd files in default path... not found
configure: error: Please reinstall the libzstd distribution
ERROR:
/tmp/pear/temp/redis/configure --with-php-config=/usr/local/php/bin/php-config --enable-redis-igbinary=yes --enable-redis-lzf=yes --enable-redis-zstd=yes' failed

libzstd找不到,需要先安装zstd库, pecl install zstd ,还是找不到,需要执行 yum -y install libzstd-devel

执行安装zstd命令/usr/local/php/bin/pecl install zstd

3.如何自动配置php.ini,不需要手动增加扩展配置。

安装完成后,需要手动配置php.ini,根据提示是因为没有配置php_ini。
install ok: channel://pecl.php.net/igbinary-3.1.5
configuration option "php_ini" is not set to php.ini location
You should add "extension=igbinary.so" to php.ini

可以通过pear设置php_ini,配置完成之后,可以自动设置php.ini文件。

查找php.ini位置:
[root@67 ~]# /usr/local/php/bin/php --ini
Configuration File (php.ini) Path: /usr/local/php/lib
Loaded Configuration File: /usr/local/php/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)

查看当前php_ini配置路径:
[root@67 ~]# /usr/local/php/bin/pear config-get php_ini

设置php_ini路径
[root@67 ~]# /usr/local/php/bin/pear config-set php_ini '/usr/local/php/lib/php.
config-set succeeded
[root@67 ~]# /usr/local/php/bin/pear config-get php_ini
/usr/local/php/lib/php.ini

重新安装igbinary后,可以正确设置php.ini,不需要再手动配置。

Build process completed successfully
Installing '/usr/local/php/include/php/ext/igbinary/src/php7/php_igbinary.h'
Installing '/usr/local/php/include/php/ext/igbinary/src/php7/igbinary.h'
Installing '/usr/local/php/include/php/ext/igbinary/php_igbinary.h'
Installing '/usr/local/php/include/php/ext/igbinary/igbinary.h'
Installing '/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/igbinary
install ok: channel://pecl.php.net/igbinary-3.1.5
Extension igbinary enabled in php.ini

4.执行命令 pecl search redis报unsupported protocol

pear.php.net is using a unsupported protocol - This should never happen.
upgrade failed

PHP PECL 升级遇到unsupported protocol 等等的问题,通常就是需要update-channels,再来执行upgrade 即可。

注:通常会需要先做pear 的channels update、upgrade

  1. pear update-channels # 与pecl update-channels 都会一起做
  2. pecl update-channels # 多做一次看看
  3. pear upgrade #通常这个做下去,pecl upgrade都一起做完了
  4. pecl upgrade # 这个应该是多做的
  5. pecl list # 检查看看版本是否都更新了
分类: linux, redis 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.