缓存技术
redis安装扩展填坑(其他扩展通用)
1.查看当前php版本
[root@hk ~]# php -v
PHP 7.0.27 (cli) (built: Jan 14 2018 09:00:22) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
2.下载获取redis
找到指定匹配版本进行下载
[root@hk ~]# wget http://pecl.php.net/get/redis-4.0.0.tgz
--2018-04-12 16:16:10-- http://pecl.php.net/get/redis-4.0.0.tgz
Resolving pecl.php.net (pecl.php.net)... 104.236.228.160
Connecting to pecl.php.net (pecl.php.net)|104.236.228.160|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 212340 (207K) [application/octet-stream]
Saving to: ‘redis-4.0.0.tgz’
100%[================================================================================================================================================>] 212,340 324KB/s in 0.6s
2018-04-12 16:16:11 (324 KB/s) - ‘redis-4.0.0.tgz’ saved [212340/212340]
解压 展开 查看目录
[root@hk ~]# tar -zxf redis-4.0.0.tgz
[root@hk ~]# cd redis-4.0.0
[root@hk redis-4.0.0]# ll
total 836
-rw-r--r-- 1 xiaoming wheel 8756 Mar 17 20:08 arrays.markdown
-rw-r--r-- 1 xiaoming wheel 75623 Mar 17 20:08 cluster_library.c
-rw-r--r-- 1 xiaoming wheel 16472 Mar 17 20:08 cluster_library.h
-rw-r--r-- 1 xiaoming wheel 10287 Mar 17 20:08 cluster.markdown
-rw-r--r-- 1 xiaoming wheel 31769 Mar 17 20:08 common.h
-rwxr-xr-x 1 xiaoming wheel 4600 Mar 17 20:08 config.m4
-rw-r--r-- 1 xiaoming wheel 923 Mar 17 20:08 config.w32
-rw-r--r-- 1 xiaoming wheel 3218 Mar 17 20:08 COPYING
-rw-r--r-- 1 xiaoming wheel 4483 Mar 17 20:08 crc16.h
-rw-r--r-- 1 xiaoming wheel 204 Mar 17 20:08 CREDITS
drwxr-xr-x 2 root root 4096 Apr 12 16:18 liblzf
-rw-r--r-- 1 xiaoming wheel 66938 Mar 17 20:08 library.c
-rw-r--r-- 1 xiaoming wheel 6537 Mar 17 20:08 library.h
-rw-r--r-- 1 xiaoming wheel 8106 Mar 17 20:08 php_redis.h
-rw-r--r-- 1 xiaoming wheel 106371 Mar 17 20:08 README.markdown
-rw-r--r-- 1 xiaoming wheel 41923 Mar 17 20:08 redis_array.c
-rw-r--r-- 1 xiaoming wheel 2033 Mar 17 20:08 redis_array.h
-rw-r--r-- 1 xiaoming wheel 37714 Mar 17 20:08 redis_array_impl.c
-rw-r--r-- 1 xiaoming wheel 1533 Mar 17 20:08 redis_array_impl.h
-rw-r--r-- 1 xiaoming wheel 111311 Mar 17 20:08 redis.c
-rw-r--r-- 1 xiaoming wheel 99664 Mar 17 20:08 redis_cluster.c
-rw-r--r-- 1 xiaoming wheel 10169 Mar 17 20:08 redis_cluster.h
-rw-r--r-- 1 xiaoming wheel 104204 Mar 17 20:08 redis_commands.c
-rw-r--r-- 1 xiaoming wheel 12160 Mar 17 20:08 redis_commands.h
-rw-r--r-- 1 xiaoming wheel 24106 Mar 17 20:08 redis_session.c
-rw-r--r-- 1 xiaoming wheel 422 Mar 17 20:08 redis_session.h
drwxr-xr-x 2 root root 4096 Apr 12 16:18 tests
查找phpize
[root@hk redis-4.0.0]# find / -name phpize
/usr/bin/phpize
[root@hk redis-4.0.0]# /usr/bin/phpize
Can't find PHP headers in /usr/include/php
The php-devel package is required for use of this command.
提示缺php-devel
安装php-devel
yum install php-devel
# 报错
Error: php70w-common conflicts with php-common-5.4.16-43.el7_4.1.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
提示要安装对应版本的 php-devel
查看yum上的资源
[root@hk redis-4.0.0]# yum list | grep php70
php70w.x86_64 7.0.27-1.w7 @webtatic
php70w-cli.x86_64 7.0.27-1.w7 @webtatic
php70w-common.x86_64 7.0.27-1.w7 @webtatic
php70w-mysql.x86_64 7.0.27-1.w7 @webtatic
php70w-pdo.x86_64 7.0.27-1.w7 @webtatic
php70w-process.x86_64 7.0.27-1.w7 @webtatic
php70w-xml.x86_64 7.0.27-1.w7 @webtatic
php70w-bcmath.x86_64 7.0.27-1.w7 webtatic
php70w-dba.x86_64 7.0.27-1.w7 webtatic
php70w-devel.x86_64 7.0.27-1.w7 webtatic
php70w-embedded.x86_64 7.0.27-1.w7 webtatic
php70w-enchant.x86_64 7.0.27-1.w7 webtatic
php70w-fpm.x86_64 7.0.27-1.w7 webtatic
php70w-gd.x86_64 7.0.27-1.w7 webtatic
php70w-imap.x86_64 7.0.27-1.w7 webtatic
php70w-interbase.x86_64 7.0.27-1.w7 webtatic
php70w-intl.x86_64 7.0.27-1.w7 webtatic
php70w-ldap.x86_64 7.0.27-1.w7 webtatic
php70w-mbstring.x86_64 7.0.27-1.w7 webtatic
php70w-mcrypt.x86_64 7.0.27-1.w7 webtatic
php70w-mysqlnd.x86_64 7.0.27-1.w7 webtatic
php70w-odbc.x86_64 7.0.27-1.w7 webtatic
php70w-opcache.x86_64 7.0.27-1.w7 webtatic
php70w-pdo_dblib.x86_64 7.0.27-1.w7 webtatic
php70w-pear.noarch 1:1.10.4-1.w7 webtatic
php70w-pecl-apcu.x86_64 5.1.9-1.w7 webtatic
php70w-pecl-apcu-devel.x86_64 5.1.9-1.w7 webtatic
php70w-pecl-geoip.x86_64 1.1.1-1.w7 webtatic
php70w-pecl-igbinary.x86_64 2.0.5-1.w7 webtatic
php70w-pecl-igbinary-devel.x86_64 2.0.5-1.w7 webtatic
php70w-pecl-imagick.x86_64 3.4.3-1.w7 webtatic
php70w-pecl-imagick-devel.x86_64 3.4.3-1.w7 webtatic
php70w-pecl-libsodium.x86_64 1.0.6-1.w7 webtatic
php70w-pecl-memcached.x86_64 3.0.4-1.w7 webtatic
php70w-pecl-mongodb.x86_64 1.3.3-1.w7 webtatic
php70w-pecl-redis.x86_64 3.1.6-1.w7 webtatic
php70w-pecl-xdebug.x86_64 2.6.0-1.w7 webtatic
php70w-pgsql.x86_64 7.0.27-1.w7 webtatic
php70w-phpdbg.x86_64 7.0.27-1.w7 webtatic
php70w-pspell.x86_64 7.0.27-1.w7 webtatic
php70w-recode.x86_64 7.0.27-1.w7 webtatic
php70w-snmp.x86_64 7.0.27-1.w7 webtatic
php70w-soap.x86_64 7.0.27-1.w7 webtatic
php70w-tidy.x86_64 7.0.27-1.w7 webtatic
php70w-xmlrpc.x86_64 7.0.27-1.w7 webtatic
找到所需的程序进行安装
[root@hk redis-4.0.0]# yum install php70w-devel.x86_64
Installed:
php70w-devel.x86_64 0:7.0.27-1.w7
Dependency Installed:
autoconf.noarch 0:2.69-11.el7 automake.noarch 0:1.13.4-3.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-Test-Harness.noarch 0:3.28-3.el7 perl-Thread-Queue.noarch 0:3.02-2.el7
Complete!
configuring 注意当前目录为radis的解压目录
[root@hk redis-4.0.0]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
[root@hk redis-4.0.0]# find / -name php-config
/usr/bin/php-config
[root@hk redis-4.0.0]# ./configure --with-php-config=/usr/bin/php-config
..........................
[root@hk redis-4.0.0]# make
/bin/sh /root/redis-4.0.0/libtool --mode=install cp ./redis.la /root/redis-4.0.0/modules
libtool: install: cp ./.libs/redis.so /root/redis-4.0.0/modules/redis.so
libtool: install: cp ./.libs/redis.lai /root/redis-4.0.0/modules/redis.la
Build complete.
[root@hk redis-4.0.0]# make install
Installing shared extensions: /usr/lib64/php/modules/
[root@hk redis-4.0.0]# ll /usr/lib64/php/modules/
[root@hk redis-4.0.0]# find / -name php.ini
/etc/php.ini
[root@hk redis-4.0.0]# vim /etc/php.ini
修改/etc/php.ini,添加下面的扩展
extension=redis.so
service httpd restart
php文件测试
<?php
redis = new Redis(); redis->connect('127.0.0.1', 6379);
redis->set('name','zhou', 10); key_1 = redis->get('name'); echo key_1;
?>