第一步:
php:php-7.0.13-Win32-VC14-x64.zip 官方下载
Apache:httpd-2.4.23-win64-VC14.zip 官方下载
Oracle:官方下载 建议百度搜索下载
VC14:vc_redist.x64.exe 官方下载 (VC11:点此下载)
Oracle Instantclient_10_2: 官方下载
php_oci8-2.1.3-7.0-ts-vc14-x64.zip:官方下载
都基于VC14下的安装包,如果是php5环境则基于VC11
第二步:
1、D盘新建目录(名字随意,这边使用phpServer)
2、解压 httpd-2.4.23-win64-VC14.zip 中的Apache24 到D:\phpServer 目录下面
3、解压 php-7.0.13-Win32-VC14-x64.zip 到D:\phpServer 目录下面 命名为php7
4、D:\phpServer 目录下面新建一个文件夹 www 用于存放网站文件
5、修改D:\phpServer\Apache24\conf 下的httpd.conf文件
37行:"ServerRoot"c:/Apache24" 改成=>"ServerRoot "D:/phpServer/Apache24"
217行:#ServerName www.example.com:80 改成=>"#ServerName localhost:80 " (将前面的 # 去掉)
247行:DocumentRoot "c:/Apache24/htdocs" 改成=> " DocumentRoot "D:/phpServer/www <Directory "D:/phpServer/www"> "
274行:<IfModule dir_module> DirectoryIndex index.html</IfModule> 改为=> "<IfModuledir_module> DirectoryIndex index.phpindex.htm index.html </IfModule>"
380行:<Directory "c:/Apache24/cgi-bin"> 改为=> "<Directory "D:/phpServer/Apache24/cgi-bin">"
注意配置文件里的路径是用 “/” !
6、底部添加
# php7 support
LoadModule php7_module "D:/phpServer/php7/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .html .htm
# configure thepath to php.ini
PHPIniDir "D:/phpServer/php7"
第三步:
1、把php7目录下的php.ini-development文件复制一份命名为php.ini
2、然后打开php.ini找到;extension=php_oci8_12c.dll ; (该dll连接Oracle12用到,当前10g用不到,保持不变),在前面加上一行extension=php_oci8.dll注意前面没有”;“号,表示加载该DLL。
3、解压php_oci8-2.1.3-7.0-ts-vc14-x64.zip中的 php_oci8.dll 到php7下的ext文件夹下
4、启动Apache了:开始---运行,输入cmd打开命令提示符,接着进入D:\phpEnv\Apache24\bin目录下回车httpd回车,没报错就启动服务成功。
可以写成bat方便使用:
同样可以写入系统服务(找度娘)@echo off cd D:\phpServer\Apache24\bin httpd pause
第四步:
1、解压instantclient-basic-win64-10.2.0.5到随意目录路径下,这里使用 C:\Program Files (x86)\instantclient_11_2
2、配置环境变量Path:C:\Program Files (x86)\instantclient_11_2; 和 D:\phpServer\php7;
第五步:
1、在www目录下新建一个index.php的文件,写入
<?php phpinfo(); ?>
2、浏览器访问localhost,看到php详细信息页。查看扩展是否开启成功
3、重新敲入访问Oracle数据库的代码:
$conn = oci_connect('user', 'pwd', '数据源名称'); if (!$conn) { $e = oci_error(); print htmlentities($e['message']); exit; }else { echo "连接oracle成功!"; }
4、网页输出 ” 连接oracle成功!“ ,即连接数据库成功
可能出现的错误:
1、call to undefined function oci_connect()......:这是因为没找到php_oci8.dll,
将php/ext目录下的php_oci8.dll文件拷贝到system32目录下,如果还不行,将Oracle 10g Instant Client安装目录下/product/10.2.0/db_2/BIN目录中的oci.dll文件拷贝到system32下。
2、OCIEnvNlsCreate() failed....... PATH includes the directory with Oracle Instant Client libraries
重启机器,如果还不行,安装Oracle 10g Instant Client