安裝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 # 檢查看看版本是否都更新了