PHP安裝ORACLE擴充(oic8安裝教程)

來源:互聯網
上載者:User

本文主要敘述,php環境與oracle資料庫不在同一台伺服器上時,php環境的安裝編譯

按照官方說明文檔 http://cn2.php.net/manual/zh/oci8.installation.php
編譯php的時候要加上這個參數–with-oci8,但是加這個參數有個前提,就是必須要安裝了對應的庫檔案。

安裝庫檔案有兩種方法:

一. 你的php環境和oracle在同一台伺服器上(通常oracle都很大,這方法不合適)
二. 在你的php伺服器上安裝 Oracle Instant Client libraries.(這個方法適合php與oracle不在一個伺服器上)

Oracle Instant Client libraries的安裝步驟:詳見 這裡
1. 針對自己的系統下載適合的Instant Client packages安裝包。其中安裝包都需要Basic或者Basic Lite包(根據本連結選擇一個系統平台,然後進去下載對應的Basic或者SDK等等包)

這裡我下載了三個zip的包,分別是:

 代碼如下 複製代碼
Instant Client Package – Basic
Instant Client Package – SQL*Plus
Instant Client Package – SDK

2. 解壓包到一個單獨的目錄,比如 “instantclient”.(我把上述三個包放到一起,然後放到了/usr/local/instantclient)

3. 在環境變數裡設定庫的載入路徑,路徑為第二部設定的路徑”instantclient”。多數UNIX平台環境變數設定LD_LIBRARY_PATH,而Windows系統應該用PATH

4. 可以開始你的應用了

載入庫(上述第3步驟,環境變數)
上述所述的庫,需要載入到linux系統才可以,那怎麼載入呢
方法一:
編輯 /etc/ld.so.conf,在裡面加入一行庫檔案路徑/usr/local/instantclient(根據實際情況而定)
注意:centos的/etc/ld.so.conf檔案裡是用include包含載入了/etc/ld.so.conf.d/*.conf所有檔案,所以我們可以建立一個檔案/etc/ld.so.conf.d/oracle.conf,在裡面加入一行庫檔案路徑/usr/local/instantclient(根據實際情況而定),而不是直接編輯/etc/ld.so.conf檔案。

方法二:

設定Linux系統設定環境變數

 

 代碼如下 複製代碼
vim ~/.bashrc

最後一行加入

 代碼如下 複製代碼


export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/instantclient

此處根據實際情況修改,因為上述第二步的instantclient位置放到了/usr/local/instantclient

編譯PHP
如果是編譯安裝php則需要加上 –with-oci8參數,因為我把Instant Client packages放在了/usr/local/instantclient
所以–with-oci8參數可以這樣寫

 代碼如下 複製代碼

–with-oci8=shared,instantclient,/usr/local/instantclient

php執行個體編譯如下:

 代碼如下 複製代碼

./configure --prefix=/usr/local/php-5.3 --with-config-file-path=/usr/local/php-5.3/etc --with-config-file-scan-dir=/usr/local/php-5.3/etc/php.d --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-openssl --enable-soap --enable-safe-mode --enable-zip --with-oci8=shared,instantclient,/usr/local/instantclient

php官方執行個體,這樣寫的./configure –with-oci8=shared,instantclient,/usr/lib/oracle//client/lib
編譯時間如提示找不到libclntsh.so,可以加個軟鏈

 代碼如下 複製代碼

ln -s /usr/local/instantclient/libclntsh.so.12.1 /usr/local/instantclient/libclntsh.so

安裝oci8拓展

使用php的pecl安裝拓展

 代碼如下 複製代碼
./pecl install oci8

在提示輸入,Instant Client packages庫的路徑時候錄入實際路徑,此處錄入:

 代碼如下 複製代碼

shared,instantclient,/usr/local/instantclient
 

[root@localhost bin]# ./pecl install oci8
downloading oci8-2.0.8.tgz ...
Starting to download oci8-2.0.8.tgz (190,854 bytes)
.........................................done: 190,854 bytes
11 source files, building
WARNING: php_bin /usr/local/php-5.3/bin/php appears to have a suffix -5.3/bin/php, but config variable php_suffix does not match
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] : shared,instantclient,/usr/local/instantclient

最後把oci8加入php.ini

 代碼如下 複製代碼

extension=oci8.so

查看phpinfo

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.