linux下安裝php的redis擴展redis.so

字號+ 編輯: 种花家 修訂: 科学鼠辈 來源: 胖达团长 CSDN 2023-09-12 我要說兩句(0)

php redis如果未經調試的情況下會出現無法支持各種壓縮方法,如果想支持這些功能,需要安裝額外的庫,在此記錄和轉發。 php安裝redis擴展,可以通過源碼編譯,也可以通過pecl來快速安裝,本文介紹通過pecl安裝redis擴展。

安装php的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, buildingrunning: 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  Can not find 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路径  Can not find the path of 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找不到,需要先用pecl安装zstd库

pecl install zstd

还是找不到, 需要执行

yum -y install libzstd-devel

If you can't find libzstd, you need to install zstd library first:

pecl install zstd

If it still doesn't work, you need to execute (on CentOS):

yum -y install libzstd-devel

执行安装zstd命令  Execute this command to install 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

pear update-channels # 与pecl update-channels 都会一起做
pecl update-channels # 多做一次看看
pear upgrade #通常这个做下去,pecl upgrade都一起做完了
pecl upgrade # 这个应该是多做的
pecl list # 检查看看版本是否都更新了


閲完此文,您的感想如何?
  • 有用

    2

  • 沒用

    0

  • 開心

    1

  • 憤怒

    0

  • 可憐

    0

1.如文章侵犯了您的版權,請發郵件通知本站,該文章將在24小時内刪除;
2.本站標注原創的文章,轉發時煩請注明來源;
3.交流群: 2702237 13835667

相關課文
  • mac開發接入微信公衆號接口返回報錯 cURL error 56: SSLRead() return error -9806

  • PHP的換行符是什麽

  • pecl安裝程序時報錯Array and string offset access syntax with curly braces is no longer supported

  • 由於商家傳入的H5交易參數有誤,該筆交易暫時無法完成,請聯繫商家解決

我要說說
網上賓友點評