PDO Driver(oci)のインストール手順覚書き。
本手順は、Oracle Database とPHPが別のマシンで動いている場合のものになります。
MDB2→PDO化を予定していましたが、残念ながら、計画が途中で頓挫したため、その後の動作確認まではできてないです。あらかじめご了承を。
手順
1. Oracle Instant Clientのインストール
本手順ではrpmを使用します。
以下、basicおよびSDKのインストール手順では、Oracle Instant Client | oracle.comのOracle Linux has Instant Client RPMs下の文章中のリンク先から適切なバージョンを取得してください。
Oracleのコチラのブログ記事によれば、Oracle Linuxは、Red Hat Enterprise Linux(RHEL)との100%の互換性があるそうです。
Red Hatや、CentOSなどいわゆるRed Hat系を使用している場合は、対応するバージョンのものを使用すればよいかと。
今回は、Oracle Instant Client Latest packages for Oracle Instant Client on Oracle Linux 7 (x86_64) より、バージョン18.5のものをダウンロード&インストールしています。
(1) RPMのダウンロード
任意のディレクトリでInstant Client Package(Basic, SDK)のRPMをダウンロードします。
URLは各ページで、対象のRPMのリンクを右クリック > 「リンクのアドレスをコピー」すれば取得できます。
# basic分
wget http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient18.5-basic-18.5.0.0.0-3.x86_64.rpm
# SDK分
wget http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient18.5-devel-18.5.0.0.0-3.x86_64.rpm
(2) RPMのインストール
インストールコマンドを実行します。
※rpm- iのうしろは、ダウンロードされたRPMの名称に変更してください。
# basic分
rpm -i oracle-instantclient18.5-basic-18.5.0.0.0-3.x86_64.rpm
# SDK分
rpm -i oracle-instantclient18.5-devel-18.5.0.0.0-3.x86_64.rpm
# インストールされたか確認
rpm -qa | grep oracle
(3) 設定
/etc/profileにライブラリパスを追加します。
vi /etc/profile
# 以下を追記
export LD_LIBRARY_PATH=/usr/lib/oracle/18.5/client64/lib:$LD_LIBRARY_PATH
# 反映
source /etc/profile
Apacheにもパスを通します。
vi etc/sysconfig/httpd
# 以下を追記
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
# Apache再起動
service httpd restart
2. OCI8のインストール
(1) PHPのディストリビューションの取得
PHPのバージョンを確認し、ダウンロードページより、対象バージョンのディストリビューションを取得します。
※旧バージョンのダウンロードはコチラ
# PHPのバージョン確認
php -v
# 対象バージョンのパッケージを取得(今回は7.4.15)
wget https://www.php.net/distributions/php-7.4.15.tar.gz
# 解凍
tar -xzvf php-7.4.15.tar.gz
(2) OCI8のインストール
オプションの1番目はinstantclient,2番目は、libclntsh.soへのパス, 18.5はインストールしたOracle instant clientのバージョンを指定します。
cd php-7.4.15/ext/oci8
phpize
./configure --with-oci8=instantclient,/usr/lib/oracle/18.5/client64/lib,18.5
make
make install
# extension_dirにoci8.soが追加されたことを確認
php -i | grep extension_dir
# 上記で出力されたディレクトリに移動
cd /usr/lib64/php/modules
ls -l oci8.so
(3) 設定
vi /etc/php.d/oci8.ini
# 以下を記載し、保存
extension=pdo_oci.so
3. PDO_OCIのインストール
OCI8のインストールと同様オプションの1番目はinstantclient,2番目は、libclntsh.soへのパス, 18.5はインストールしたOracle instant clientのバージョンを指定します。
(1)PDO_OCIのインストール
cd php-7.4.15/ext/pdo_oci
phpize
./configure --with-pdo-oci=instantclient,/usr/lib/oracle/18.5/client64/lib,18.5
make
make install
# extension_dirにpdo_oci.soが追加されたことを確認
cd /usr/lib64/php/modules
ls -l pdo_oci.so
(2) 設定
vi /etc/php.d/pdo_oci.ini
# 以下を記載し、保存
extension=pdo_oci.so
(3) PDO Driverの確認
以下のコマンドを実行し、PDO driversの一覧にociが表示されていればOK
php -i | grep "PDO drivers"
参考
本記事の大部分を@bluemooninc さんの
既存のCentOS7にoci8とpdo_ociを追加する手順書 | Qiita
をベースとさせていただきました。ありがとうございました!
その他参考にしたページたち
- CentOSに代わる安定したRHEL互換OSをお求めでしょうか?Oracle Linuxを検討すべき3つの理由 | Oracle Technology Network Japan Blog
- Unsupported Historical Releases | php.net
- Oracle 関数 (PDO_OCI) | php.net
- Oracle Instant Client | oracle.com
- 要件(PDO_OCI) | php.net
- インストール手順(OCI8)| php.net
- 6.2 Oracle Database Instant Clientのインストール | Oracle® R Enterpriseインストレーションおよび管理ガイド リリース1.5.1