1.32 php动态扩展模块安装
注: 本节操作使用PHP7。
查看PHP模块:
[root@cham002 ~]# /usr/local/php/bin/php -m[PHP Modules]bz2CorectypedatedomeregexiffileinfofiltergdhashiconvjsonlibxmlmbstringmcryptmysqlmysqliopensslpcrePDOpdo_mysqlpdo_sqlitePharposixReflectionsessionSimpleXMLsoapsocketsSPLsqlite3standardtokenizerxmlxmlreaderxmlwriterzlib[Zend Modules]
安装Redis模块
redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)和zset(有序集合)。
[root@cham002 ~]# cd /usr/local/src/[root@cham002 src]# lsapr-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.gzapr-1.6.3.tar.gz httpd-2.4.29 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz php-7.1.6apr-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]# lsapr-1.6.3 httpd-2.4.29 php-5.6.30 phpredis-develop.zipapr-1.6.3.tar.gz httpd-2.4.29.tar.gz php-5.6.30.tar.gzapr-util-1.6.1 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz php-7.1.6apr-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]# lsarrays.markdown config.m4 debian library.h README.markdown redis.c redis_session.ccluster_library.c config.w32 debian.control mkdeb-apache2.sh redis_array.c redis_cluster.c redis_session.hcluster_library.h COPYING ISSUE_TEMPLATE.md mkdeb.sh redis_array.h redis_cluster.h rpmcluster.markdown crc16.h liblzf package.xml redis_array_impl.c redis_commands.c serialize.listcommon.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: 20160303Zend Module Api No: 20160303Zend Extension Api No: 320160303[root@cham002 phpredis-develop]# echo $?0#没有出错 如果报以下错:安装autoconf这个包 yum install -y autoconfCannot find autoconf. Please check your autoconf installation and the$PHP_AUTOCONF environment variable. Then, rerun this script.[root@cham002 phpredis-develop]# lsacinclude.m4 common.h COPYING library.c package.xml redis_cluster.c serialize.listaclocal.m4 config.guess crc16.h library.h php_redis.h redis_cluster.h testsarrays.markdown config.h.in CREDITS ltmain.sh README.markdown redis_commands.cautom4te.cache config.m4 debian Makefile.global redis_array.c redis_commands.hbuild config.sub debian.control missing redis_array.h redis_session.ccluster_library.c configure install-sh mkdeb-apache2.sh redis_array_impl.c redis_session.hcluster_library.h configure.in ISSUE_TEMPLATE.md mkdeb.sh redis_array_impl.h rpmcluster.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 installInstalling 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-20160303sqlite3.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 redisredis
关于扩展板块
在PHP的源码包中没有第三方模块的包,但是在PHP源码包的/ext/目录下有好多扩展模块,如果所需要的扩展模块在该目录下,可以直接进行安装:
[root@cham002 phpredis-develop]# cd /usr/local/src/php-7.1.6/[root@cham002 php-7.1.6]# lsacinclude.m4 EXTENSIONS Makefile.fragments README.EXT_SKEL run-tests.phpaclocal.m4 footer Makefile.gcov README.GIT-RULES sapiappveyor generated_lists Makefile.global README.input_filter scriptsbuild genfiles Makefile.objects README.MAILINGLIST_RULES server-tests-config.phpbuildconf header makerpm README.md server-tests.phpbuildconf.bat include meta_ccld README.namespaces snapshotCODING_STANDARDS INSTALL missing README.NEW-OUTPUT-API stamp-h.inconfig.guess install-sh mkinstalldirs README.PARAMETER_PARSING_API stub.cconfig.log libphp7.la modules README.REDIST.BINS testsconfig.nice libs netware README.RELEASE_PROCESS travisconfig.status libtool NEWS README.SELF-CONTAINED-EXTENSIONS TSRMconfig.sub LICENSE pear README.STREAMS UPGRADINGconfigure ltmain.sh php7.spec README.SUBMITTING_PATCH UPGRADING.INTERNALSconfigure.in main php7.spec.in README.TESTING vcscleanCONTRIBUTING.md makedist php.gif README.TESTING2 win32CREDITS Makefile php.ini-development README.UNIX-BUILD-SYSTEM Zendext Makefile.frag php.ini-production README.WIN32-BUILD-SYSTEM[root@cham002 php-7.1.6]# ls extbcmath dom gd json odbc pdo_mysql pspell snmp sysvshm xslbz2 enchant gettext ldap opcache pdo_oci readline soap tidy zipcalendar exif gmp libxml openssl pdo_odbc recode sockets tokenizer zlibcom_dotnet ext_skel hash mbstring pcntl pdo_pgsql reflection spl wddxctype ext_skel_win32.php iconv mcrypt pcre pdo_sqlite session sqlite3 xmlcurl fileinfo imap mysqli pdo pgsql shmop standard xmlreaderdate filter interbase mysqlnd pdo_dblib phar simplexml sysvmsg xmlrpcdba 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/phpizeConfiguring for:PHP Api Version: 20160303Zend Module Api No: 20160303Zend 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 installInstalling 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