標籤:
需求&背景
最近根據項目需求,要在php中遠端連線Oracel 11g Express資料庫,為了開發方便,決定採用pdo,也就是php的PDO_OCI擴充,但是php安裝的時候並沒有安裝PDO_OCI擴充,所以現在需要新增一個php擴充。
解決方案
首先上google搜尋了一下,找到一片文章:http://shiki.me/blog/installing-pdo_oci-and-oci8-php-extensions-on-centos-6-4-64bit/, 這篇文章講的很詳細,非常感謝作者!
我在這裡再簡略總結一下:
-
首先要安裝Oracle資料庫的InstantClient: :http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html。根據自己的系統,選擇合適的安裝包,Basic和devel兩個包都需要安裝。因為我的伺服器上並沒有安裝Oracle 11g Express資料庫,所以需要安裝, 如果伺服器上已經裝好了Oracle 11g Express資料庫, 這一步應該是可以忽略的(僅僅是一個猜測,沒有測試)
-
從pear下載PDO_OCI的源碼包 (https://pecl.php.net/package/PDO_OCI), 選擇1.0的stable版本即可, 可以使用wget直接下載到linux, 或者使用pecl命令(推薦):
$ pecl download PDO_OCI $ tar -xvf PDO_OCI-1.0.tgz$ cd PDO_OCI-1.0
因為PDO_OCI這個擴充已經很久沒有更新了,需要編輯config.m4這個檔案以支援11g或者更高版本的資料庫, 具體如下:
在第10行左右添加如下代碼:
elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then PDO_OCI_VERSION=11.2
在101行左右添加如下代碼:
11.2) PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD) ;;
-
然後就是用phpize這個工具進行編譯安裝:
$ phpize //如果系統提示沒有找到這個命令,只需要安裝php-devel即可//$ yum install php-devel$ ./configure --with-pdo-oci=instantclient,/usr,11.2$ make$ sudo make install
我在運行 ./configure --with-pdo-oci=instantclient,/usr,11.2後得到一個錯誤: checking for oci.h... configure: error: I‘m too dumb to figure out where the include dir is in your instant client install 意思是說, 沒有找到instant client 的include 檔案夾, 這是為什麼呢?繼續google, 這個問題不多見,我花了很多時間在這個問題上面。最後看到一片文章下的評論:
Changes for x86_64 November 10th 2010 at 09:11 am Some changes were required to get the configure to work on a 64 bit Redhat (Fedora 13) system.
We installed the 64 bit version of oracle-instantclient-{devel,basic}.
These installed in:
/usr/lib/oracle/11.2/client64
/usr/include/oracle/11.2/client64
We created symlinks as follows:
/usr/lib/oracle/11.2/client -> /usr/lib/oracle/11.2/client64
/usr/include/oracle/11.2/client -> /usr/include/oracle/11.2/client64
Then the "./configure --with-pdo-oci=instantclient,/usr,11.2" command worked fine!
The reason for the symlinks instead of changing the variables in the oracle.sh is that the build/configure scripts seem to be hard coded for "client" (not client64) in many places. It was easer to create 2 symlinks than to change all the code in every script/config file.
非常感謝這問網友。大概意思是在configure時尋找的檔案夾是/usr/lib/oracle/11.2/client 和/usr/include/oracle/11.2/client, 這兩個檔案夾位置的組成方式是:${prefix}/lib OR lib/oracle/${version}/client,而64bit 的Instant Client的安裝目錄都是client64,所以configure的時候找不到,解決這個問題只需要添加兩個符號連結即可:
$ 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
添加好符號連結後,再次執行
$ ./configure --with-pdo-oci=instantclient,/usr,11.2$ make$ sudo make install
執行成功, 沒有報錯。
-
make install 成功之後,在 /usr/lib64/php/modules/ 就會出現pdo_oci.so,然後在php的設定檔中啟用pdo_oci擴充:
$ vi /etc/php.d/pdo_oci.ini
新增內容: extension=pdo_oci.so
重啟apache就可以使用PDO_OCI擴充了。
本文著作權屬作者所有,轉載請註明出處: http://www.cnblogs.com/jpdoutop/p/Install-PDO_OCI-extension-On-Linux-64bit.html
在CentOS 6.7 64位安裝PHP的PDO_OCI擴充 Installing PDO_OCI extension on CentOS 6.7 64bit