11.32 php扩展模块安装
·查看PHP模块
/usr/local/php7/bin/php -m
忘记安装或者需求变更,需要增加模块
下面安装一个redis的模块(通常在LAMP架构下当做缓存来用)
[root@localhost php-7.1.6]# cd /usr/local/src/
[root@localhost src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop
(过程省略)
[root@localhost src]# mv develop phpredis-develop.zip ##改名
[root@localhost src]# unzip phpredis-develop.zip
(过程省略)
[root@localhost phpredis-develop]# yum install -y autoconf
(过程省略)
[root@localhost 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@localhost phpredis-develop]# ls
acinclude.m4 cluster.markdown configure.in install-sh missing redis_array.c redis_commands.c tests
aclocal.m4 common.h config.w32 ISSUE_TEMPLATE.md mkdeb-apache2.sh redis_array.h redis_commands.h
arrays.markdown config.guess COPYING liblzf mkdeb.sh redis_array_impl.c redis_session.c
autom4te.cache config.h.in crc16.h library.c mkinstalldirs redis_array_impl.h redis_session.h
build config.m4 CREDITS library.h package.xml redis.c rpm
cluster_library.c config.sub debian ltmain.sh php_redis.h redis_cluster.c run-tests.php
cluster_library.h configure debian.control Makefile.global README.markdown redis_cluster.h serialize.list
[root@localhost phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config
(编译过程省略)
[root@localhost phpredis-develop]# make && make install
(过程省略)
Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
make install会把redis.so放在 /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/ 中
[root@localhost phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so redis.so
(PHP还不支持redis,需要加载redis.so)
·查看扩展模块存放目录,我们可以在php.ini中去自定义该路径
[root@localhost phpredis-develop]# /usr/local/php7/bin/php -i |grep -i 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
编辑/usr/local/php7/etc/php.ini,增加一行配置(可以放到文件最后一行)
extension = redis.so
[root@localhost phpredis-develop]# /usr/local/php7/bin/php -m |grep redis
redis
如果想编译一个模块时,如果php源码包中的ext文件夹下自带了该目录,那么不用下载就可以直接编译,如果没有,那么就需要去下载
在php源码包里有很多模块,我们安装一个没有加载的zip模块
[root@localhost src]# cd php-7.1.6/ext/
[root@localhost ext]# ls
bcmath dba filter imap mcrypt pcntl pdo_odbc readline snmp sysvsem xmlrpc
bz2 dom ftp interbase mysqli pcre pdo_pgsql recode soap sysvshm xmlwriter
calendar enchant gd intl mysqlnd pdo pdo_sqlite reflection sockets tidy xsl
com_dotnet exif gettext json oci8 pdo_dblib pgsql session spl tokenizer zip
ctype ext_skel gmp ldap odbc pdo_firebird phar shmop sqlite3 wddx zlib
curl ext_skel_win32.php hash libxml opcache pdo_mysql posix simplexml standard xml
date fileinfo iconv mbstring openssl pdo_oci pspell skeleton sysvmsg xmlreader
[root@localhost ext]# /usr/local/php7/bin/php -m |grep zip ##没有zip模块
[root@localhost ext]# cd zip/
[root@localhost zip]# ls
config.m4 config.w32 CREDITS examples lib LICENSE_libzip php_zip.c php_zip.h tests TODO zip_stream.c
[root@localhost zip]# /usr/local/php7/bin/phpize ##执行,生成./configure
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
[root@localhost zip]# ls
acinclude.m4 build config.m4 configure.in examples LICENSE_libzip missing php_zip.h TODO
aclocal.m4 config.guess config.sub config.w32 install-sh ltmain.sh mkinstalldirs run-tests.php zip_stream.c
autom4te.cache config.h.in configure CREDITS lib Makefile.global php_zip.c tests
[root@localhost zip]# ./configure --with-php-config=/usr/local/php7/bin/php-config
(编译过程省略)
[root@localhost zip]# make && make install
[root@localhost zip]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303
redis.so zip.so
[root@localhost zip]# vim /usr/local/php7/etc/php.ini
extension=zip.so
/usr/local/php7/bin/php -m |grep zip
zip