首页 > 数据库 > Oracle > 正文

PHP下的Oracle客户端扩展(OCI8)安装教程

2021-11-23 22:57:16
字体:
来源:转载
供稿:网友

这篇文章主要介绍了PHP下的Oracle客户端扩展(OCI8)安装教程,本文在Linux系统中实现,OCI8是用来连接Oracle数据库的PHP扩展模块,需要的朋友可以参考下

最近的项目需要用php访问oracle数据库,不得不在linux下给php安装oci8扩展。php也可以使用pdo访问oracle数据库,但还是需要安装客户端。

首先到oracle官网的这个页面下载相关的文件,注意要连数据库服务器的版本,一定要对应,否则安装成功也会连不上,同时也要区分32位、64位服务器,比如我要连的数据库服务器是oracle10.2.0.4,64位主机,那么我要下载下面三个文件:

  1. oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm 
  2. oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm 
  3. oracle-instantclient-sqlplus-10.2.0.4-1.x86_64.rpm 

1.用以下命令安装,代码如下:

  1. # rpm -ivh oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm    oracle-instantclient-sqlplus-10.2.0.4-1.x86_64.rpm 

2.安装OCI8 PHP扩展,代码如下:

  1. # yum install libaio 
  2. # cd ~ 
  3. # wget http://pecl.php.net/get/oci8-1.3.5.tgz 

3.然后执行命令,代码如下:

  1. # tar zxvf oci8-1.3.5.tgz 
  2. # cd oci8-1.3.5/ 
  3. # /usr/local/php5/bin/phpize  CFLAGS=/usr/lib/oracle/11.2/client64/ CXXFLAGS=/usr/lib/oracle/11.2/client64/ 
  4. # ./configure --with-php-config=/usr/local/php5/bin/php-config --with-oci8=instantclient,/usr/lib/oracle/11.2/client64/lib/ 
  5. # make 
  6. # make install(这里多运行几次,直到出现如下提示) 
  7.  
  8. [root@webserver02 oci8-1.3.5]# make install 
  9. /bin/sh /root/oci8-1.3.5/libtool --mode=install cp ./oci8.la /root/oci8-1.3.5/modules 
  10. cp ./.libs/oci8.so /root/oci8-1.3.5/modules/oci8.so 
  11. cp ./.libs/oci8.lai /root/oci8-1.3.5/modules/oci8.la 
  12. PATH="$PATH:/sbin" ldconfig -n /root/oci8-1.3.5/modules 
  13. ---------------------------------------------------------------------- 
  14. Libraries have been installed in: 
  15.    /root/oci8-1.3.5/modules 
  16. If you ever happen to want to link against installed libraries 
  17. in a given directory, LIBDIR, you must either use libtool, and 
  18. specify the full pathname of the library, or use the `-LLIBDIR' 
  19. flag during linking and do at least one of the following: 
  20.    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable 
  21.      during execution 
  22.    - add LIBDIR to the `LD_RUN_PATH' environment variable 
  23.      during linking 
  24.    - use the `-Wl,--rpath -Wl,LIBDIR' linker flag 
  25.    - have your system administrator add LIBDIR to `/etc/ld.so.conf' 
  26.  
  27. See any operating system documentation about shared libraries for 
  28. more information, such as the ld(1) and ld.so(8) manual pages. 
  29. ---------------------------------------------------------------------- 
  30. Installing shared extensions:     /usr/local/php5/lib/php/extensions/no-debug-zts-20090626/ 
  31. # cd /usr/local/php5/lib 

4.创建ext目录,代码如下:

# mkdir ext/

把oci8.so文件拷贝到php.ini 的ext目录里面,代码如下:

# cp /root/oci8-1.3.5/modules/oci8.so /usr/local/php5/lib/ext/

5.在php.ini里面加上extension=oci8.so

如下:

  1. extension_dir = "/usr/local/php5/lib/ext" 
  2. extension = "oci8.so" 
  3. session.save_path = "/tmp/php" 
  4. oci8.privileged_connect = on 

重启apache服务:

/usr/local/apache2/bin/apachectl stop

/usr/local/apache2/bin/apachectl start

刷新测试页面。发现oci8出现了,则大功告成.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表