CENTOS6下PHP 安裝 oci8 pdo-oci

來源:互聯網
上載者:User

標籤:rac   安裝   sid   shell   ofo   man   tcl   擴充   for   

摘要: 最近一個項目需要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.rpmrpm -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-develexport 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/libmakemake install

在/etc/php.d目錄下增加設定檔20-oci8.ini

extension=oci8.so

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

php -i | grep oci8

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

/etc/php.d/oci8.ini, oci8oci8.connection_class => no value => no valueoci8.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.tgzcd 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.2makemake 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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.