标签:win32 dll phar libxml wget write session script zlib
11.32 PHP扩展模块安装
php模块已经安装、编译好了,但发现少了一个模块(安装时忘记/需求变更),此时可以以扩展模块形式编译一个新模块(.so文件)
redis:一个nosql,通常在lamp架构下被当做一个缓存使用
以扩展模块的形式编译安装一个redis模块:
1 下载redis的安装包
[root@hyc-01-01 src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop
2 解压包
[root@hyc-01-01 src]# mv develop phpredis-develop.zip
[root@hyc-01-01 src]# unzip phpredis-develop.zip
3 在phpredis-develop.zip解压后的文件中生成configure目录
要./configure生成可编译文件就必须要在解压后的包里有这个目录,否则无法配置
[root@hyc-01-01 phpredis-develop]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script. 报错
缺少包autoconf
[root@hyc-01-01 phpredis-develop]# yum install -y autoconf
[root@hyc-01-01 phpredis-develop]# /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
正常执行
[root@hyc-01-01 phpredis-develop]# ls
acinclude.m4 config.m4 install-sh package.xml redis_commands.h
aclocal.m4 config.sub ISSUE_TEMPLATE.md php_redis.h redis_session.c
arrays.markdown configure liblzf README.markdown redis_session.h
autom4te.cache configure.in library.c redis_array.c rpm
build config.w32 library.h redis_array.h run-tests.php
cluster_library.c COPYING ltmain.sh redis_array_impl.c serialize.list
cluster_library.h crc16.h Makefile.global redis_array_impl.h tests
cluster.markdown CREDITS missing redis.c
common.h debian mkdeb-apache2.sh redis_cluster.c
config.guess debian.control mkdeb.sh redis_cluster.h
config.h.in INSTALL.markdown mkinstalldirs redis_commands.c
[root@hyc-01-01 phpredis-develop]# pwd
/usr/local/src/phpredis-develop
4 生成可编译文件
[root@hyc-01-01 phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config
5 编译并安装
[root@hyc-01-01 phpredis-develop]# make
[root@hyc-01-01 phpredis-develop]# 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@hyc-01-01 phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/opcache.so redis.so
检查php支持的扩展模块:
[root@hyc-01-01 phpredis-develop]# /usr/local/php7/bin/php -m|grep redis
发现php支持的扩展模块中不包含redis模块
配置在php加载redis模块:
找到扩展模块所在路径:
[root@hyc-01-01 lib]# /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模块配置文件:
[root@hyc-01-01 lib]# vim /usr/local/php7/etc/php.ini
…
920
921 ;extension=php_soap.dll
922 ;extension=php_sockets.dll
923 ;extension=php_sqlite3.dll
924 ;extension=php_tidy.dll
925 ;extension=php_xmlrpc.dll
926 ;extension=php_xsl.dll
927 extension=redis.so
…
[root@hyc-01-01 lib]# /usr/local/php7/bin/php -m|grep redis
redis redis模块加载成功
redis等模块属于第三方,不是php自带,使用时需要专门下载
在php源码包中有ext目录,该目录下有很多模块:
[root@hyc-01-01 php-7.1.6]# ls ext
bcmath ext_skel interbase opcache pdo_sqlite skeleton tokenizer
bz2 ext_skel_win32.php intl openssl pgsql snmp wddx
calendar fileinfo json pcntl phar soap xml
com_dotnet filter ldap pcre posix sockets xmlreader
ctype ftp libxml pdo pspell spl xmlrpc
curl gd mbstring pdo_dblib readline sqlite3 xmlwriter
date gettext mcrypt pdo_firebird recode standard xsl
dba gmp mysqli pdo_mysql reflection sysvmsg zip
dom hash mysqlnd pdo_oci session sysvsem zlib
enchant iconv oci8 pdo_odbc shmop sysvshm
exif imap odbc pdo_pgsql simplexml tidy
[root@hyc-01-01 php-7.1.6]# pwd
/usr/local/src/php-7.1.6
若ext目录下存在某个包,则在安装配置模块时不需要下载,只要进入对应包的目录,执行/usr/local/php7/bin/phpize即可在该目录下生成configure文件,然后再生成可编译文件,编译、安装即可
生成可编译文件(即执行./configure时)需要跟参数--with-php-config=/usr/local/php7/bin/php-config
标签:win32 dll phar libxml wget write session script zlib
原文地址:http://blog.51cto.com/12216458/2156669