windows下PHP的oci和pdo_oci扩展安装

配置环境: 
- windows server 2012 
- PHP Version 7.1.11
- Oracle Database



安装oci扩展

PHP官方说明

Configuring PHP with OCI8

Review the previous Requirements section before configuring OCI8.

To enable the OCI8 extension, configure PHP with the option –with-oci8 . 
翻译:打开–with-oci8配置即可开启OCI8扩展

Before starting the web server, OCI8 typically requires several Oracle environment variables (see below) to locate libraries, point to configuration files, and set some basic properties such as the character set used by Oracle libraries. The variables should be set before any PHP process starts.

PHP should be run with the same, or more recent, major version of Oracle libraries as it was configured with. For example, if you build OCI8 with Oracle 11.2 libraries, then PHP should also be deployed and run with Oracle 11.2 libraries. 
翻译:PHP需要配置与连接的oracle数据库相同版本或者更新版本的OCI扩展库。

……

Installing OCI8 on Windows

On Windows, uncomment the php.ini line extension=php_oci8.dll when using Oracle 10gR2 client libraries. Uncomment extension=php_oci8_11g.dll when using Oracle 11g client libraries. These two DLLs contain equivalent functionality and only one may be enabled at a time. Make sure extension_dir is set to the directory containing the PHP extension DLLs.

If using Instant Client, set the system PATH environment variable to the Oracle library directory. 
翻译:如果使用Instant Client,设置环境变量指向oralce目录

根据PHP手册得到配置步骤:

  1. 配置php.ini,打开extension=php_oci8_12c.dll,如果PHP版本非文章中的版本,应该是php_oci8.dll或者php_oci8_11g.dll,这里要根据你使用的oralce版本来选择。dll文件版本高的兼容版本低的,版本低的无法兼容版本高的。

  2. 安装oralce Instant Client,下载连接。自己选择环境版本,不要搞错操作系统位数就行。

  3. Instant Client目录中的oci.dll放进windows\system32目录

  4. 将自己下载的Instant Client,放到自己的软件目录里。然后在环境变量的PATH里面加入Instant Client的路径。重启电脑使环境变量生效。(不重启也可,自行baidu)

  5. 测试连接oracle是否成功。

安装pdo_oci扩展

如果你已经安装OK了oci扩展,那么仅需要将extension=php_pdo_oci.dll打开即可。如果没有则执行安装oci扩展里面2和3步骤。别忘了重启WEB服务器。