11.32 php扩展模块安装
·查看PHP模块
/usr/local/php7/bin/php -m
忘记安装或者需求变更,需要增加模块
下面安装一个redis的模块(通常在LAMP架构下当做缓存来用)
[[email protected] php-7.1.6]# cd /usr/local/src/ [[email protected] src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop (过程省略) [[email protected] src]# mv develop phpredis-develop.zip ##改名 [[email protected] src]# unzip phpredis-develop.zip (过程省略) [[email protected] phpredis-develop]# yum install -y autoconf (过程省略) [[email protected] phpredis-develop]# /usr/local/php7/bin/phpize ##生成./configure Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 [[email protected] 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 [[email protected] phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config (编译过程省略) [[email protected] 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/ 中
[[email protected] phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/ opcache.so redis.so
(PHP还不支持redis,需要加载redis.so)
·查看扩展模块存放目录,我们可以在php.ini中去自定义该路径
[[email protected] 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
[[email protected] phpredis-develop]# /usr/local/php7/bin/php -m |grep redis redis
如果想编译一个模块时,如果php源码包中的ext文件夹下自带了该目录,那么不用下载就可以直接编译,如果没有,那么就需要去下载
在php源码包里有很多模块,我们安装一个没有加载的zip模块
[[email protected] src]# cd php-7.1.6/ext/ [[email protected] 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 [[email protected] ext]# /usr/local/php7/bin/php -m |grep zip ##没有zip模块 [[email protected] ext]# cd zip/ [[email protected] zip]# ls config.m4 config.w32 CREDITS examples lib LICENSE_libzip php_zip.c php_zip.h tests TODO zip_stream.c [[email protected] zip]# /usr/local/php7/bin/phpize ##执行,生成./configure Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 [[email protected] 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 [[email protected] zip]# ./configure --with-php-config=/usr/local/php7/bin/php-config (编译过程省略) [[email protected] zip]# make && make install [[email protected] zip]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303 redis.so zip.so [[email protected] zip]# vim /usr/local/php7/etc/php.ini extension=zip.so /usr/local/php7/bin/php -m |grep zip zip
原文地址:http://blog.51cto.com/11530642/2083990
时间: 2024-10-28 14:39:42