在php编译完成后,如果想增加一个功能模块,要么重新编译php,要么直接编译一个扩展模块。重新编译php会影响现网中的业务,因此直接编译扩展模块更好些。
1
|
[root@juispan ~]
# /usr/local/php/bin/php -m ##查看php加载的功能模块
|
下面演示安装redis扩展模块:
1、下载安装包
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@juispan ~]
# cd /usr/local/src
[root@juispan src]
# wget https://codeload.github.com/phpredis/phpredis/zip/develop
--2017-07-22 01:30:22-- https:
//codeload
.github.com
/phpredis/phpredis/zip/develop
正在解析主机 codeload.github.com (codeload.github.com)... 192.30.255.120, 192.30.255.121
正在连接 codeload.github.com (codeload.github.com)|192.30.255.120|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:221385 (216K) [application
/zip
]
正在保存至: “develop”
100%[=====================================================================================================================================================>] 221,385 36.6KB
/s
用时 5.9s
2017-07-22 01:30:30 (36.6 KB
/s
) - 已保存 “develop” [221385
/221385
])
|
2、解压压缩包
1
2
|
[root@juispan src]
# mv develop phpredis-develop.zip
[root@juispan src]
# unzip phpredis-develop.zip
|
3、生成configure文件
1
2
3
4
5
6
7
8
9
10
|
[root@juispan src]
# cd phpredis-develop
[root@juispan phpredis-develop]
# /usr/local/php/bin/ph
phar phar.phar php php-cgi php-config phpize
[root@juispan phpredis-develop]
# /usr/local/php/bin/phpize
Configuring
for
:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
Cannot
find
autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
|
报错,安装autoconf后,再次执行。
1
2
3
4
5
|
[root@juispan phpredis-develop]
# /usr/local/php/bin/phpize
Configuring
for
:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
|
4、加载配置
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@juispan phpredis-develop]
# ./configure --with-php-config=/usr/local/php/bin/php-config
checking
for
grep
that handles long lines and -e...
/usr/bin/grep
checking
for
egrep
...
/usr/bin/grep
-E
checking
for
a
sed
that does not truncate output...
/usr/bin/sed
checking
for
cc... cc
checking whether the C compiler works...
yes
......
creating libtool
appending configuration tag
"CXX"
to libtool
configure: creating .
/config
.status
config.status: creating config.h
[root@juispan phpredis-develop]
# echo $?
0
|
5、编译与编译安装
1
2
3
|
[root@juispan phpredis-develop]
# make &&make install
[root@juispan phpredis-develop]
# echo $?
0
|
6、编辑php配置
1
2
3
4
5
6
7
|
[root@juispan phpredis-develop]
# /usr/local/php/bin/php -i | grep extension_dir
extension_dir =>
/usr/local/php/lib/php/extensions/no-debug-zts-20131226
=>
/usr/local/php/lib/php/extensions/no-debug-zts-20131226
sqlite3.extension_dir => no value => no value
[root@juispan phpredis-develop]
# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226
opcache.so redis.so
[root@juispan phpredis-develop]
# vi /usr/local/php/etc/php.ini
extension = redis.so
##增加一行
|
7、检查效果
1
2
|
[root@juispan phpredis-develop]
# /usr/local/php/bin/php -m |grep redis
redis
|
如果想在php网站使用redis模块,需要重启httpd服务。
本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1953716,如需转载请自行联系原作者