1.32 php动态扩展模块安装
注: 本节操作使用PHP7。
查看PHP模块:
[root@cham002 ~]# /usr/local/php/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
安装Redis模块
redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)和zset(有序集合)。
[root@cham002 ~]# cd /usr/local/src/
[root@cham002 src]# ls
apr-1.6.3 apr-util-1.6.1.tar.bz2 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz php-5.6.30.tar.gz
apr-1.6.3.tar.gz httpd-2.4.29 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz php-7.1.6
apr-util-1.6.1 httpd-2.4.29.tar.gz php-5.6.30 php-7.1.6.tar.bz2
[root@cham002 src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop
--2017-12-27 02:00:01-- 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
长度:未指定 [application/zip]
正在保存至: “develop”
[ <=> ] 228,014 129KB/s 用时 1.7s
2017-12-27 02:00:04 (129 KB/s) - “develop” 已保存 [228014]
[root@cham002 src]# du -sh develop
224K develop
[root@cham002 src]# mv develop phpredis-develop.zip
[root@cham002 src]# ls
apr-1.6.3 httpd-2.4.29 php-5.6.30 phpredis-develop.zip
apr-1.6.3.tar.gz httpd-2.4.29.tar.gz php-5.6.30.tar.gz
apr-util-1.6.1 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz php-7.1.6
apr-util-1.6.1.tar.bz2 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz php-7.1.6.tar.bz2
[root@cham002 src]# unzip phpredis-develop.zip
[root@cham002 src]# cd phpredis-develop/
[root@cham002 phpredis-develop]# ls
arrays.markdown config.m4 debian library.h README.markdown redis.c redis_session.c
cluster_library.c config.w32 debian.control mkdeb-apache2.sh redis_array.c redis_cluster.c redis_session.h
cluster_library.h COPYING ISSUE_TEMPLATE.md mkdeb.sh redis_array.h redis_cluster.h rpm
cluster.markdown crc16.h liblzf package.xml redis_array_impl.c redis_commands.c serialize.list
common.h CREDITS library.c php_redis.h redis_array_impl.h redis_commands.h tests
[root@cham002 phpredis-develop]# /usr/local/php7/bin/phpize
#执行该命令的目的是生成configure文件,否则无法进行编译安装
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
[root@cham002 phpredis-develop]# echo $?
0
#没有出错 如果报以下错:安装autoconf这个包 yum install -y autoconf
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
[root@cham002 phpredis-develop]# ls
acinclude.m4 common.h COPYING library.c package.xml redis_cluster.c serialize.list
aclocal.m4 config.guess crc16.h library.h php_redis.h redis_cluster.h tests
arrays.markdown config.h.in CREDITS ltmain.sh README.markdown redis_commands.c
autom4te.cache config.m4 debian Makefile.global redis_array.c redis_commands.h
build config.sub debian.control missing redis_array.h redis_session.c
cluster_library.c configure install-sh mkdeb-apache2.sh redis_array_impl.c redis_session.h
cluster_library.h configure.in ISSUE_TEMPLATE.md mkdeb.sh redis_array_impl.h rpm
cluster.markdown config.w32 liblzf mkinstalldirs redis.c run-tests.php
开始安装
环境配置
[root@cham002 phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config
完成后检测
[root@cham002 phpredis-develop]# echo $?
0
编译&安装
[root@cham002 phpredis-develop]# make
[root@cham002 phpredis-develop]# echo $?
0
[root@cham002 phpredis-develop]# make install
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
[root@cham002 phpredis-develop]# echo $?
0
[root@cham002 phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so redis.so
为PHP加载Redis模块
先查看扩展模块所在目录:
[root@cham002 phpredis-develop]# /usr/local/php7/bin/php -i |grep extension_dir
extension_dir => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303 => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303
sqlite3.extension_dir => no value => no value
说明: 该目录可以在PHP配置文件php.ini中进行设置(保持默认)
加载Redis模块
编辑PHP的配置文件:
[root@cham002 phpredis-develop]# vim /usr/local/php7/etc/php.ini
说明: 在配置文件中加入“extension=redis.so”即可!该文件中“;”表示注释符号,同“#”。
[root@cham002 phpredis-develop]# /usr/local/php7/bin/php -m |grep redis
redis
关于扩展板块
在PHP的源码包中没有第三方模块的包,但是在PHP源码包的/ext/目录下有好多扩展模块,如果所需要的扩展模块在该目录下,可以直接进行安装:
[root@cham002 phpredis-develop]# cd /usr/local/src/php-7.1.6/
[root@cham002 php-7.1.6]# ls
acinclude.m4 EXTENSIONS Makefile.fragments README.EXT_SKEL run-tests.php
aclocal.m4 footer Makefile.gcov README.GIT-RULES sapi
appveyor generated_lists Makefile.global README.input_filter scripts
build genfiles Makefile.objects README.MAILINGLIST_RULES server-tests-config.php
buildconf header makerpm README.md server-tests.php
buildconf.bat include meta_ccld README.namespaces snapshot
CODING_STANDARDS INSTALL missing README.NEW-OUTPUT-API stamp-h.in
config.guess install-sh mkinstalldirs README.PARAMETER_PARSING_API stub.c
config.log libphp7.la modules README.REDIST.BINS tests
config.nice libs netware README.RELEASE_PROCESS travis
config.status libtool NEWS README.SELF-CONTAINED-EXTENSIONS TSRM
config.sub LICENSE pear README.STREAMS UPGRADING
configure ltmain.sh php7.spec README.SUBMITTING_PATCH UPGRADING.INTERNALS
configure.in main php7.spec.in README.TESTING vcsclean
CONTRIBUTING.md makedist php.gif README.TESTING2 win32
CREDITS Makefile php.ini-development README.UNIX-BUILD-SYSTEM Zend
ext Makefile.frag php.ini-production README.WIN32-BUILD-SYSTEM
[root@cham002 php-7.1.6]# ls ext
bcmath dom gd json odbc pdo_mysql pspell snmp sysvshm xsl
bz2 enchant gettext ldap opcache pdo_oci readline soap tidy zip
calendar exif gmp libxml openssl pdo_odbc recode sockets tokenizer zlib
com_dotnet ext_skel hash mbstring pcntl pdo_pgsql reflection spl wddx
ctype ext_skel_win32.php iconv mcrypt pcre pdo_sqlite session sqlite3 xml
curl fileinfo imap mysqli pdo pgsql shmop standard xmlreader
date filter interbase mysqlnd pdo_dblib phar simplexml sysvmsg xmlrpc
dba ftp intl oci8 pdo_firebird posix skeleton sysvsem xmlwriter
现在扩展模块中没有zip
[root@cham002 php-7.1.6]# /usr/local/php7/bin/php -m |grep zip
现在扩展模块中没有zip
[root@cham002 php-7.1.6]# cd ext
[root@cham002 ext]# cd zip
[root@cham002 zip]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
#执行该命令的目的是生成configure文件,否则无法进行编译安装
[root@cham002 zip]# ./configure --with-php-config=/usr/local/php7/bin/php-config
[root@cham002 zip]# echo $?
0
接下来就make我出现了这种错误。没有没有截图。可以用#make clean
然后在重新执行命令
[root@cham002 zip]# make install
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
[root@cham002 zip]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so redis.so zip.so