查看PHP模块
[root@centos6 ~]# php -m
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
如果我们发现有一个模块没有编译进来,解决办法有两种:第一,需要重新编译,重新配置;第二,单独编译该模块,使用动态共享的方式加载该模块。我们自己尝试编译一个PHP动态共享模块。
PHP安装包的ext目录下包含了许多模块的源代码:
[root@centos6 ~]# cd /usr/local/src/php-5.4.36
[root@centos6 php-5.4.36]# cd ext
[root@centos6 ext]# ls
bcmath dba fileinfo iconv mbstring odbc pdo_mysql posix simplexml standard wddx zlib
bz2 dom filter imap mcrypt openssl pdo_oci pspell skeleton sybase_ct xml
calendar enchant ftp interbase mssql pcntl pdo_odbc readline snmp sysvmsg xmlreader
com_dotnet ereg gd intl mysql pcre pdo_pgsql recode soap sysvsem xmlrpc
ctype exif gettext json mysqli pdo pdo_sqlite reflection sockets sysvshm xmlwriter
curl ext_skel gmp ldap mysqlnd pdo_dblib pgsql session spl tidy xsl
date ext_skel_win32.php hash libxml oci8 pdo_firebird phar shmop sqlite3 tokenizer zip
PHP默认没有没有安装curl模块,下面命令返回无结果:
[root@centos6 ext]# php -m |grep -i curl
我们以编译安装PHP的curl模块为例进行说明:进入curl目录
[root@centos6 ext]# cd curl
[root@centos6 curl]# ls
config.m4 config.w32 CREDITS curl.dsp interface.c multi.c package.xml php_curl.h streams.c tests
生成configure相关的文件:
[root@centos6 curl]# yum install -y m4 autoconf #安装两个自动生成configure的工具
[root@centos6 curl]# /usr/local/php/bin/phpize #生成configure
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
[root@centos6 curl]# ls
acinclude.m4 config.h.in config.w32 ltmain.sh package.xml
aclocal.m4 config.m4 CREDITS Makefile.global php_curl.h
autom4te.cache config.sub curl.dsp missing run-tests.php
build configure install-sh mkinstalldirs streams.c
config.guess configure.in interface.c multi.c tests
配置
[root@centos6 curl]# ./configure --with-php-config=/usr/local/php/bin/php-config
错误1:configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
解决:[root@centos6 curl]# yum -y install curl-devel
编译
[root@centos6 curl]# make
[root@centos6 curl]# echo $?
0
安装
[root@centos6 curl]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
[root@centos6 curl]# echo $?
0
模块已生成
[root@centos6 curl]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
curl.so
查看extension_dir
[root@centos6 curl]# php -i |grep extension_dir
extension_dir => /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525 => /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525
sqlite3.extension_dir => no value => no value
[root@centos6 curl]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
curl.so
也可以自定义extension_dir
[root@centos6 curl]# vim /usr/local/php/etc/php.ini
……
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"
……
配置加载curl.so
……
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
extension=curl.so
……
查看动态加载的模块
[root@centos6 curl]# php -m |grep curl
curl
转载于:https://blog.51cto.com/rachy/1892323