Windows 下安装扩展库

在 Windows 下安装完 PHP 和 web 服务器之后,可能想要安装一些扩展库来获得更多功能。可以通过修改 php.ini 来选择当 PHP 启动时加载哪些扩展库。也可以在脚本中通过使用 dl() 来动态加载。

PHP 扩展库的 DLL 文件都具有 php_ 前缀。

很多扩展库都内置于 Windows 版的 PHP 之中。这意味着要加载这些扩展库不需要额外的 DLL 文件和 extension 配置指令。Windows 下的 PHP 扩展库列表列出了需要或曾经需要额外 PHP DLL 文件的扩展库。下面是内置的扩展库列表:

PHP 4 中(截止到 PHP 4.3.11):BCMathCaledarCOMCtypeFTPMySQLODBCOverloadPCRESessionTokenizerWDDXXMLZlib

PHP 5 中(截止到 5.0.4)有以下修改。新增内置:DOMLibXMLIconvSimpleXMLSPLSQLite。以下不再内置:MySQLOverload

PHP 搜索扩展库的默认位置在 PHP 4 中是 C:\php4\extensions,在 PHP 5 中是 C:\php5。要修改此项以符合用户自己的 PHP 设置,需要编辑 php.ini 文件:

  • 需要修改 extension_dir 设置以指向用户放置扩展库的目录或者说放置 php_*.dll 文件的位置。例如:

    extension_dir = C:\php\extensions

  • 要在 php.ini 中启用某扩展库,需要去掉该行 extension=php_*.dll 前的注释符号,将想要加载的扩展库前的分号(;)删除即可。

    例子 6-8. 启用 Bzip2 扩展库

    // 将这一行
    ;extension=php_bz2.dll
    
    // 改成这样
    extension=php_bz2.dll

  • 有些扩展库需要额外的 DLL 才能工作。其中一部分包括在发行包里,PHP 4 中在 C:\php\dlls\ 目录下,PHP 5 中在主目录下,但还有一些,例如 Oracle(php_oci8.dll)所需要的 DLL 没有绑定在发行包里。如果安装 PHP 4,将绑定的 DLL 从 C:\php\dlls 拷贝到主目录 C:\php 中。别忘了将 C:\php 放到系统路径 PATH 中去(此过程在另外的 FAQ 条目中有说明)。

  • 某些 DLL 没有绑定在 PHP 发行包中,详情见每个扩展库的文档页。此外有关 PECL 的说明见手册页 PECL 扩展库安装。在 PECL 中有日益增加数目巨大的 PHP 扩展库,这些扩展库需要单独下载

注: 如果运行服务器模块版的 PHP,在修改了 php.ini 之后别忘了重新启动 web 服务器以使其改动生效。

下表说明了哪些扩展库需要额外的 DLL。

表格 6-1. PHP 扩展库

扩展库说明注解
php_bz2.dllbzip2 压缩函数库
php_calendar.dll历法转换函数库自 PHP 4.0.3 起内置
php_cpdf.dllClibPDF 函数库
php_crack.dll密码破解函数库
php_ctype.dllctype 家族函数库自 PHP 4.3.0 起内置
php_curl.dllCURL,客户端 URL 库函数库需要:libeay32.dllssleay32.dll(已附带)
php_cybercash.dll网络现金支付函数库PHP <= 4.2.0
php_db.dllDBM 函数库已废弃。用 DBA 替代之(php_dba.dll
php_dba.dllDBA:数据库(dbm 风格)抽象层函数库
php_dbase.dlldBase 函数库
php_dbx.dlldbx 函数库 
php_domxml.dllDOM XML 函数库 PHP <= 4.2.0 需要:libxml2.dll(已附带),PHP >= 4.3.0 需要:iconv.dll(已附带)
php_dotnet.dll.NET 函数库PHP <= 4.1.1
php_exif.dllEXIF 函数库 需要 php_mbstring.dll。并且在 php.ini 中,php_exif.dll 必须在 php_mbstring.dll之后加载。
php_fbsql.dllFrontBase 函数库PHP <= 4.2.0
php_fdf.dllFDF:表单数据格式化函数库需要:fdftk.dll(已附带)
php_filepro.dllfilePro 函数库只读访问
php_ftp.dllFTP 函数库自 PHP 4.0.3 起内置
php_gd.dllGD 库图像函数库 在 PHP 4.3.2 中删除。此外注意在 GD1 中不能用真彩色函数,用 php_gd2.dll 替代。
php_gd2.dllGD 库图像函数库GD2
php_gettext.dllGettext 函数库 PHP <= 4.2.0 需要 gnu_gettext.dll(已附带),PHP >= 4.2.3 需要 libintl-1.dlliconv.dll(已附带)。
php_hyperwave.dllHyperWave 函数库
php_iconv.dllICONV 字符集转换需要:iconv-1.3.dll(已附带),PHP >=4.2.1 需要 iconv.dll
php_ifx.dllInformix 函数库需要:Informix 库
php_iisfunc.dllIIS 管理函数库
php_imap.dllIMAP,POP3 和 NNTP 函数库
php_ingres.dllIngres II 函数库需要:Ingres II 库
php_interbase.dllInterBase functions需要:gds32.dll(已附带)
php_java.dllJava 函数库PHP <= 4.0.6 需要:jvm.dll(已附带)
php_ldap.dllLDAP 函数库 PHP <= 4.2.0 需要 libsasl.dll(已附带),PHP >= 4.3.0 需要 libeay32.dllssleay32.dll(已附带)
php_mbstring.dll多字节字符串函数库
php_mcrypt.dllMcrypt 加密函数库需要:libmcrypt.dll
php_mhash.dllMhash 函数库PHP >= 4.3.0 需要:libmhash.dll(已附带)
php_mime_magic.dllMimetype 函数库需要:magic.mime(已附带)
php_ming.dllMing 函数库(Flash)
php_msql.dllmSQL 函数库需要:msql.dll(已附带)
php_mssql.dllMSSQL 函数库需要:ntwdblib.dll(已附带)
php_mysql.dllMySQL 函数库PHP >= 5.0.0 需要 libmysql.dll(已附带)
php_mysqli.dllMySQLi 函数库PHP >= 5.0.0 需要 libmysql.dll(PHP <= 5.0.2 中是 libmysqli.dll)(已附带)
php_oci8.dllOracle 8 函数库需要:Oracle 8.1+ 客户端库
php_openssl.dllOpenSSL 函数库需要:libeay32.dll(已附带)
php_oracle.dllOracle 函数库需要:Oracle 7 客户端库
php_overload.dll对象重载函数库自 PHP 4.3.0 起内置
php_pdf.dllPDF 函数库
php_pgsql.dllPostgreSQL 函数库
php_printer.dll打印机函数库
php_shmop.dll共享内存函数库
php_snmp.dllSNMP 函数库仅用于 Windows NT!
php_soap.dllSOAP 函数库PHP >= 5.0.0
php_sockets.dllSocket 函数库
php_sybase_ct.dllSybase 函数库需要:Sybase 客户端库
php_tidy.dllTidy 函数库PHP >= 5.0.0
php_tokenizer.dllTokenizer 函数库自 PHP 4.3.0 起内置
php_w32api.dllW32api 函数库
php_xmlrpc.dllXML-RPC 函数库PHP >= 4.2.1 需要 iconv.dll(已附带)
php_xslt.dllXSLT 函数库 PHP <= 4.2.0 需要 sablot.dllexpat.dll(已附带)。PHP >= 4.2.1 需要 sablot.dllexpat.dlliconv.dll(已附带)。
php_yaz.dllYAZ 函数库需要:yaz.dll(已附带)
php_zip.dllZip 文件函数库只读访问
php_zlib.dllZLib 压缩函数库自 PHP 4.3.0 起内置


add a note add a note User Contributed Notes
Freddo
12-Oct-2006 09:11
We tried to install PHP 4 ISAPI Module on IIS 6 on a Windows Server 2003 SP2 at the office.

The only way we found out to make these extensions work, is by putting the extensions DLLs in the System32\inetsrv in the Windows directory. We did the same previously with the
php4isapi.dll and php4ts.dll to make PHP work. The system was asking for a password previously.

We cannot explain it, it seems like a problem only occuring with SP2 installed because we never had this problem before. Giving the right permission to the PHP and extensions folders didn't do anything good. It always gave use a permission denied error. We even tried to give full control to Everyone on the PHP folder, same result.

I hope it can help.
no at ddress dot com
30-Sep-2006 01:56
I am trying in vein to activate the php_gd2.dll extension with Apache 2.0.59 and php 5.1.6

In my php.ini file I have the following:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "C:/Webserver/php/ext"

and a little further down I have removed the ; (semi-colon) from ;extension=php_gd2.dll making it extension=php_gd2.dll

Also the above .dll is listed correctly within C:\Webserver\php\ext

Finally, my php.ini file has been saved and my HTTP Server has been restarted correctly according to the Apache Service Monitor but checking <? phpinfo(); ?> the GDLib is not listed... Please someone help me here before I lose all my hair!
elsint at yahoo dot com
27-Sep-2006 02:38
Installing PHP5.1.6 on an IIS5.1 system.

Some extensions are not working because of registry(like LDAP).

You need to create a registry file named: "inifilepath.reg"
Content should be the 3 lines under,be sure to define your PHP path correct:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\PHP]
"IniFilePath"="C:\\PHP"

After creating this file, double click it, click yes, and restart IIS. Hopefully this might solve problem for some, as it solved for me.
simi_def at c2 dot hu
18-Aug-2006 04:10
I had problems with PHP5/Apache2.2/MySQL 5 installation on a WinXp machine.

I got the

Fatal error: call to undefined function - mysql_connect().

message

Solution :
1, use correct version of ext\php_mysql.dll and libmysql.dll
2, !!! edit the CORRECT php.ini (%windir%\php.ini) like c:\windows\php.ini !!!
3, add php installation dir to PATH
4, edit php.ini to load extension php_mysql.dll

use
<?php
phpinfo
();
?>
to check.
hevesir at t-mobile dot hu
07-Apr-2006 04:54
If You try to install PHP5 to IIS6 with Oracle....

Then You need some kind of pilot-exams, not for big planes, just a little one.

So: After installations (php.ini is correct see above ie.: extenstion = php_oci8.dll etc)

If You use anonymous access, You'll  have a builtin user to use it. Make this user local administrator, or give minimum read access to PHP folder (ie.: c:\php) and ORAHOME (ie. c:\ora92) folders.

If You use Windows Integrated authentication, give for Domain Users minimum read access to PHP folder (ie.: c:\php) and ORAHOME (ie. c:\ora92) folders.

Goog luck.
sopp_ladios at hotmail dot com
20-Aug-2004 12:35
[editor note: this should be fixed in PHP 5.1.0]

The order of the extensions listed in php.ini is causing problems... one must check that a particular extension A is enabled and above extension B if B requires A to be enabled.
The original ordering doesnt make sure that this always happens (ie, A is above B)

I came into this problem when I tried to enable the exif extension under windows. I knew mbstring is required but I kept getting errors even after I enabled both.
The problem can only be fixed by moving the mbstring line above the exif line...