linux(ubuntu 21.10): php8.0.14:安装phpredis以访问redis(phpredis-5.3.5)
一,检查当前安装的php是否支持访问redis
1,在phpinfo的输出信息中搜索redis
2,从命令行检查模块是否已安装?
root@lhdpc:/data/php/admapi# php --ri redis Extension 'redis' not present.
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/05/29/linux-ubuntu-21-10-php8-14-an-zhuang-phpredis-yi-fang-wen/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,安装phpredis:
1,官方地址
https://github.com/phpredis/phpredis/tags
2,下载:
root@lhdpc:/usr/local/source# wget https://github.com/phpredis/phpredis/archive/refs/tags/5.3.5.tar.gz
3,解压:
root@lhdpc:/usr/local/source# tar -zxvf 5.3.5.tar.gz
4,phpize(用来编译php的扩展库)
root@lhdpc:/usr/local/source# cd phpredis-5.3.5/ root@lhdpc:/usr/local/source/phpredis-5.3.5# /usr/local/soft/php8/bin/phpize Configuring for: PHP Api Version: 20200930 Zend Module Api No: 20200930 Zend Extension Api No: 420200930 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
说明:此处提示找不到autoconf,需要安装:
root@lhdpc:/usr/local/source/phpredis-5.3.5# apt-get install autoconf
安装完成后,再次执行phpize
root@lhdpc:/usr/local/source/phpredis-5.3.5# /usr/local/soft/php8/bin/phpize Configuring for: PHP Api Version: 20200930 Zend Module Api No: 20200930 Zend Extension Api No: 420200930
说明:这次执行成功了
5,配置,需要指定相应php的php-config的路径
root@lhdpc:/usr/local/source/phpredis-5.3.5# ./configure --with-php-config=/usr/local/soft/php8/bin/php-config
6,安装:
root@lhdpc:/usr/local/source/phpredis-5.3.5# make && make install … Installing shared extensions: /usr/local/soft/php8/lib/php/extensions/no-debug-non-zts-20200930/
7,在提示的目录下查看已安装的phpredis模块:
liuhongdi@lhdpc:~$ ls /usr/local/soft/php8/lib/php/extensions/no-debug-non-zts-20200930/ opcache.so redis.so
8,配置php.ini,引入redis模块:
root@lhdpc:/usr/local/source/phpredis-5.3.5# vi /usr/local/soft/php8/etc/php.ini
添加一行:
extension=/usr/local/soft/php8/lib/php/extensions/no-debug-non-zts-20200930/redis.so
9,重启php-fpm
root@lhdpc:/usr/local/source/phpredis-5.3.5# systemctl restart php-fpm.service
三,查看安装的效果:
1,从命令行查看
root@lhdpc:/usr/local/source/phpredis-5.3.5# php --ri redis redis Redis Support => enabled Redis Version => 5.3.5 Redis Sentinel Version => 0.1 Available serializers => php, json Directive => Local Value => Master Value redis.arrays.algorithm => no value => no value redis.arrays.auth => no value => no value redis.arrays.autorehash => 0 => 0 redis.arrays.connecttimeout => 0 => 0 redis.arrays.distributor => no value => no value redis.arrays.functions => no value => no value redis.arrays.hosts => no value => no value redis.arrays.index => 0 => 0 redis.arrays.lazyconnect => 0 => 0 redis.arrays.names => no value => no value redis.arrays.pconnect => 0 => 0 redis.arrays.previous => no value => no value redis.arrays.readtimeout => 0 => 0 redis.arrays.retryinterval => 0 => 0 redis.arrays.consistent => 0 => 0 redis.clusters.cache_slots => 0 => 0 redis.clusters.auth => no value => no value redis.clusters.persistent => 0 => 0 redis.clusters.read_timeout => 0 => 0 redis.clusters.seeds => no value => no value redis.clusters.timeout => 0 => 0 redis.pconnect.pooling_enabled => 1 => 1 redis.pconnect.connection_limit => 0 => 0 redis.pconnect.echo_check_liveness => 1 => 1 redis.pconnect.pool_detect_dirty => 0 => 0 redis.pconnect.pool_poll_timeout => 0 => 0 redis.pconnect.pool_pattern => no value => no value redis.session.locking_enabled => 0 => 0 redis.session.lock_expire => 0 => 0 redis.session.lock_retries => 10 => 10 redis.session.lock_wait_time => 2000 => 2000
2,从phpinfo的输出信息查看:
四,查看php的版本:
root@lhdpc:/usr/local/source/phpredis-5.3.5# php --version PHP 8.0.14 (cli) (built: Dec 23 2021 11:52:42) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.14, Copyright (c) Zend Technologies with Zend OPcache v8.0.14, Copyright (c), by Zend Technologies
五,查看linux的版本:
root@lhdpc:/usr/local/source/phpredis-5.3.5# cat /etc/os-release PRETTY_NAME="Ubuntu 21.10" NAME="Ubuntu" VERSION_ID="21.10" VERSION="21.10 (Impish Indri)" VERSION_CODENAME=impish ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=impish