php7.2安裝OCI8擴充套件支援oracle資料庫

語言: CN / TW / HK

持續創作,加速成長!這是我參與「掘金日新計劃 · 6 月更文挑戰」的25天,點選檢視活動詳情

做專案的時候,遠端的oracle資料庫為我們提供一張中間表,我這邊業務中的一些資料是需要到oracle資料庫中的這張中間表去查詢的。

PHP連線oracle資料庫。需要用到OCI8的擴充套件。說來慚愧,工作這麼多年,還沒有正經的使用過oracle資料庫。

mysql資料庫的語法跟oracle資料庫的語法是不一樣的,別跟我似的上來就用mysql的語法來操作oracle資料庫……有點丟人了……

今天我們大概記錄一下OCI8擴充套件的安裝過程。

一:下載檔案

1 :oracle官網下載地址:

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

下載檔案(看準了檔名):

``` oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm

oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm ```

2 :PHP官網下載地址:

https://www.php.net/manual/zh/oci8.installation.php

PHP-OCI8外掛

下載命令:

wget http://pecl.php.net/get/oci8-2.2.0.tgz

建議將以上三個檔案放入/opt目錄下,當然,具體放哪是你的自由。能找到就行。

二:安裝

1 :安裝oracle外掛

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

可能會報錯:

ImportError: libaio.so.1: cannot open shared object file: No such file or directory”

報錯原因上邊已經給出,缺少libiao外掛,解決方法:

yum install libaio

2 :安裝OCI8外掛

(1):解壓tar包:

tar -zxf oci8-2.2.0.tgz

(2):進入解壓目錄

cd oci8-2.2.0

(3):執行一下命令:

phpize

執行的時候可能會出現一下錯誤:Can't find PHP headers in /usr/include/php The php-devel package is required for use

解決方案

yum install php72w-devel #注意一下,這條命令取決你安裝的PHP版本,我這個命令並不適用所有人

(4):使用$ORACLE_HOME或Instant Client配置軟體包

./configure --with-oci8=shared,instantclient,/usr/lib/oracle/<version>/client/lib

./configure -with-oci8=shared,$ORACLE_HOME

(5):執行編譯安裝:

make install

這裡可能會報錯:

make: No rule to make target build', needed bydefault'. Stop.*

解決方案:

1:安裝如下配置:

yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel

2: 重新 configure

./configure

3: 編譯

make && make install

(6):配置php.ini

我們在PHP的配置檔案php.ini中加上

extension=oci8.so

重啟PHP systemctl restart php-fpm

重啟web伺服器(nginx、apache等)。 systemctl restart nginx

檢視PHPinfo();如下圖所示:

1629702279967283.png

然後,你就可以在你的PHP框架中配置多個數據庫連結了。

有好的建議,請在下方輸入你的評論。

歡迎訪問個人部落格:https://guanchao.site

歡迎訪問我的小程式:開啟微信->發現->小程式->搜尋“時間裡的”