## 在 Windows 上安装 PHP 扩展

### 去哪里找扩展库？

PHP 扩展库通常称为“php_*.dll”（其中星号代表具体某扩展的名字），位于“PHP\ext”目录下。

PHP 发行包中包括了大多数开发者最常用到的扩展库。这些被称为“核心”扩展库。

### 下载哪个扩展？

• 不同的版本号（至少前两个数字要一致）
• 不同的线程安全性设定
• 不同的处理器体系（x86，x64，...)
• 不同的排错设定
• 其它

 <?phpphpinfo();?> 

drive:\\path\to\php\executable\php.exe -i


### 载入一个扩展

;extension=php_extname.dll

extension=php_extname.dll

; PHP version 7.2 开始的推荐写法：
extension=extname
zend_extension=another_extension


Configuration File (php.ini) Path  C:\WINDOWS

Loaded Configuration File   C:\Program Files\PHP\5.2\php.ini


### 解决问题

 This is handwaved somewhat in the "Resolving problems" section, but mis-location of (non-extension) DLL files is often a problem when installing PHP extensions on Windows.Many PHP extensions come with not only the extension DLL, but supplementary DLLs that are required by that extension. (For example, php_luasandbox.dll comes with lua5.1.dll, the lua interpreter it sandboxes.) Those other DLLs should go into the same directory as the php.exe binary, NOT the extension directory.So, if php_luasandbox.dll is installed at C:\PHP8.1\ext\php_luasandbox.dll, the interpreter would be located at C:\PHP8.1\lua5.1.dll. That allows the PHP binary C:\PHP8.1\php.exe to find those additional DLLs when required. 
 On windows, drop your extension's dependencies into a dir of your choice, but outside of your php install. Add that dir to a path environment variable used by your php. Add <extension_name>.dll to your php's extension_dir, and update your php.ini (unless you're simply testing with php's cli). 
 In addition to the helpful comments of ferdnyc and dario: A few weeks ago I've set up a new W11 using PHP 8.1. (as a module) with Apache. It was working fine.Today i wanted to install the PECL-extension php-amqp. This extension comes with two additional files that are said to be placed in PHPs main directory. It worked fine running from the command prompt but with Apache the extension failed with "Unable to load dynamic library 'amqp'".I tried 100 ways to notate paths in php.ini and http.conf: c:, C:, \, \\, /, ". I also installed a new PHP in the root to get rid of the space in the path. It did not help.When reading dario's comment i stumbeled across him mentioning "path environment variable". I checked that in Window's settings and I realized, that i had added PHP's path to the USER'S path-settings, but not to the SYSTEM'S path. That is why it worked in the command prompt but not when starting Apache as a service. After adding it there it worked fine.