1. 程式人生 > >CENTOS6下PHP 安裝 oci8 pdo-oci

CENTOS6下PHP 安裝 oci8 pdo-oci

literal pic onf -i brush bash .sh x86_64 nvi

摘要: 最近一個項目需要php對Oracle支持,所以要部署這個環境。

服務器是yum配置的amp環境,本著不重新編譯的原則去操作。本機已有環境為PHP,apache,mysql,需要連oracle數據庫,所以需要打開oracle擴展。我們需要做的工作有:安裝oracle客戶端、pdo_oci擴展、oci8擴展。

前期準備工作:

$ sudo yum install php-pear php-devel zlib zlib-devel bc libaio glibc
$ sudo yum groupinstall "Development Tools"

因為擴展還是需要重新編譯,所以對編譯器也進行了,更新。

yum install gcc-c++
yum install gcc-g77

目標數據庫是11g,去Oracle官網下載對應版本(沒搞過oracle至少我們這麽理解的),

官網下載地址:

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

下載文件:

oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm

oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

php擴展文件下載:

http://pecl.php.net/package/PDO_OCI PDO_OCI-1.0.tgz Oracle的PDO接口

http://pecl.php.net/package/oci8 oci8-2.0.8.tgz Oracle擴展

安裝:

安裝Oraclecient

技巧:

rpm -qpl 可以查看rpm包會在哪些路徑安裝文件

1.安裝rpm包

rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

以下幾條命令僅供參考:

rpm -qa | grep oracle     //查看oracle是否安裝  
rpm -qa   //查看所有已安裝的人rpm包  
rpm -e oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm //卸載已安裝的rpm包  
rpm -ivh --force oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm //強制安裝rpm包

2. 配置

修改/etc/ld.so.conf 或在ld.so.conf.d文件夾下添加oracle-x86_64.conf文件,寫入安裝oracle客戶端的lib路徑:

#vi /etc/ld.so.conf  
/usr/lib/oracle/11.2/client64/lib/     //加入此行,保存退出

或者

echo ‘/usr/lib/oracle/11.2/client64/lib/‘ > /etc/ld.so.conf.d/oracle-x86_64.conf

64位系統需要創建32位的軟鏈接(這裏可能是一個遺留bug,不然後面編譯會出問題)

ln -s /usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client  
ln -s /usr/include/oracle/11.2/client64 /usr/include/oracle/11.2/client

定義環境變量

vi etc/profile

加入以下幾行

export ORACLE_HOME=/usr/lib/oracle/11.2/client64/  
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64:$LD_LIBRARY_PATH  
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"

命令行輸入以下語句使環境配置立即生效

#source /etc/profile

據說還可以這樣,僅供參考:

Create a file inside /etc/profile.d named oracle.sh and put this as the content:

export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib

And run it so we’ll have LD_LIBRARY_PATH as an environment variable.

source /etc/profile.d/oracle.sh

安裝oci8

編譯的時候會出現錯誤:

error: oci8_dtrace_gen.h: No such file or directory

如果需要 DTRACE:

yum install systemtap-sdt-devel
export PHP_DTRACE=yes

如果不需要 DTRACE:

modify the file ‘php_oci8_int.h‘, change the 48th line

#include "oci8_dtrace_gen.h" to #undef HAVE_OCI8_DTRACE

一切就緒,編譯安裝

tar -xvf oci8-2.0.8.tgz  
cd oci8-2.0.8.tgz


/usr/bin/phpize
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib
make
make install

在/etc/php.d目錄下增加配置文件20-oci8.ini

extension=oci8.so

用下面命令查看是否成功:

php -i | grep oci8

你可以看到下面類似的內容:

/etc/php.d/oci8.ini, oci8
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100 oci8.events => Off => Off oci8.max_persistent => -1 => -1 oci8.old_oci_close_semantics => Off => Off oci8.persistent_timeout => -1 => -1 oci8.ping_interval => 60 => 60 oci8.privileged_connect => Off => Off oci8.statement_cache_size => 20 => 20

安裝PDO_OCI

tar -xvf PDO_OCI-1.0.tgz
cd PDO_OCI-1.0


防止pdo_oci對oracle11支持不足(pdo_oci可能不支持oracle11g,需要做個軟鏈接成作為oracle10版本才能編譯過去):

ln -s /usr/include/oracle/11.2 /usr/include/oracle/10.2.0.1  
ln -s /usr/lib/oracle/11.2 /usr/lib/oracle/10.2.0.1


還可以:
Inside the PDO_OCI-1.0 folder, edit the file named config.m4.
Find a pattern like this near line 10 and add these 2 lines:

elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then
  PDO_OCI_VERSION=11.2

Find a pattern like this near line 101 and add these lines:

11.2)
  PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
  ;;


編譯的時候我還遇到了其他問題

pdo_oci.c:34: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pdo_oci_functions’

在pdo_oci.c文件中

function_entry 改成 zend_function_entry

一切就緒,開始編譯安裝

/usr/bin/phpize
./configure --with-pdo-oci=instantclient,/usr,11.2
make
make install

在 /etc/php.d 目錄下 新建文件 30-pdo_oci.ini
寫入

extension=pdo_oci.so

用下面命令查看是否安裝成功

php -i | grep oci


你會見到類似下面的內容

/etc/php.d/pdo_oci.ini,
PDO drivers => oci, odbc, sqlite

至此結束,請運行phpinfo()看看吧。

CENTOS6下PHP 安裝 oci8 pdo-oci