OCI8 を構成する前に前述の 要件 節に 目を通してください。
OCI8 エクステンションを有効にするには、オプション --with-oci8 とともに PHP を構成します。
Web サーバーを開始する前に、一般的に OCI8 はいくつかの Oracle 環境変数(下記参照)を 必要とします。それらはライブラリの場所を指定したり、構成ファイルを指示したり、 Oracle ライブラリで使用する文字セットのような基本的ないくつかのプロパティを設定します。 あらゆる PHP プロセスが開始される 前にそれらの変数が設定されるべきです。
PHP should be run with the same, or more recent, major version of Oracle libraries as it was configured with. For example, if you build OCI8 with Oracle 11.2 libraries, then PHP should also be deployed and run with Oracle 11.2 libraries.
構成 shared オプションでは、 PHP に動的にロードできるように OCI8 を共有ライブラリとしてビルドします。 共有エクステンションをビルドすることにより、 PHP のほかの部分に影響を与えることなく、 OCI8 を簡単に更新出来ます。
下記の構成オプションの一つを使って OCI8 を構成します
Oracle Instant Client を使用している場合、こうします
./configure --with-oci8=shared,instantclient,/path/to/instant/client/lib
Instant Client を ZIP ファイルからインストールした場合、例えば ln -s libclntsh.so.11.1 libclntsh.so のようにライブラリのシンボリックリンクを作成したことを確認してください。
RPM ベースの Oracle Instant Client インストールを使った場合、 構成の行はこのようになります。
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/<version>/client/lib
例えば、 --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client/lib.
Oracle Instant Client は PHP バージョン 4.3.11 と 5.0.4 で最初にサポートされ、 PHP を構成するために当初は --with-oci8-instant-client オプションが使用されていたことに注意してください。
Oracle データベース、または Oracle Client のフルインストールを使用している場合、こうします
./configure --with-oci8=shared,$ORACLE_HOME
Web サーバーのユーザー (nobody, www) が、 $ORACLE_HOME ディレクトリ配下のライブラリ、初期化ファイル、 (使用されていれば) tnsnames.ora を利用する権利を 所持していることを確認してください。 Oracle 10gR2 では、ディレクトリ利用権を与えるために $ORACLE_HOME/install/changePerm.sh ユーティリティを実行する必要があるでしょう。
構成後、通常の PHP ビルド処理を続行します。例えば、 make install 。 OCI8 共有エクステンション oci8.so ライブラリが作成されます。 php.ini ファイルの extension_dir オプションで 示される、 PHP エクステンションディレクトリに手動で移動する必要があるでしょう。
OCI8 のインストールを完了するために、 php.ini を編集して行を追加します。
extension=oci8.so
下記の構成オプションの一つを使って OCI8 を構成します
Oracle Instant Client を使用している場合、こうします
./configure --with-oci8=instantclient,/path/to/instant/client/lib
Oracle データベース、または Oracle Client のフルインストールを使用している場合、こうします
./configure --with-oci8=$ORACLE_HOME
構成後、通常の PHP ビルド処理を続行します。例えば、 make install 。 コンパイル成功後、 php.ini ファイルに oci8.so を追加する必要はありません。 追加のビルドステップは不要です。
The OCI8 extension can be added to an existing PHP installation either automatically or manually from » http://pecl.php.net/.
For an automated install follow these steps:
If you are behind a firewall, set PEAR's proxy, for example:
pear config-set http_proxy http://my-proxy.example.com:80/
Run
pecl install oci8
When prompted, enter either the value of $ORACLE_HOME, or instantclient,/path/to/instant/client/lib.
Note: Do not enter the variable $ORACLE_HOME because it will not be expanded. Instead, enter the actual path of the Oracle home directory.
For a manual install, download the PECL OCI8 package, e.g. oci8-1.3.5.tgz.
Extract the package:
tar -zxf oci8-1.3.5.tgz cd oci8-1.3.5
Prepare the package:
phpize
Configure the package, either using $ORACLE_HOME or Instant Client
./configure -with-oci8=shared,$ORACLE_HOME
or
./configure -with-oci8=shared,instantclient,/path/to/instant/client/lib
Install the package:
make install
After either an automatic or manual install, edit your php.ini file and add the line:
extension=oci8.so
Make sure the php.ini directive extension_dir is set to the directory that oci8.so was installed in.
On Windows, uncomment the php.ini line extension=php_oci8.dll when using Oracle 10gR2 client libraries. Uncomment extension=php_oci8_11g.dll when using Oracle 11g client libraries. These two DLLs contain equivalent functionality and only one may be enabled at a time. Make sure extension_dir is set to the directory containing the PHP extension DLLs.
If using Instant Client, set the system PATH environment variable to the Oracle library directory.
このエクステンションを使用する前に、 Web デーモンのユーザーのために Oracle の環境変数が 適切に設定されたか確認してください。 もし Web サーバーがブート時に自動起動される場合は、ブート時の環境も正しく設定されていることを 確認してください。
注意: PHP スクリプトで putenv() を使って Oracle の環境変数を 設定しないでください。それは、スクリプトが実行される前に Oracle のライブラリがロードされて 初期化されるかもしれないからです。 putenv() で変数を設定すると、コンフリクト、クラッシュ、 または予測出来ない動作の原因となるかもしれません。 ある関数は動作し、他の関数は捉えがたいエラーを示すかもしれません。 Web サーバー開始前に変数を設定するべきです。
Red Hat Linux と変種では、 /etc/sysconfig/httpd の最後で変数を export してください。 Apache 2 を伴う他のシステムでは Apache bin ディレクトリーで envvars スクリプトを使用するかもしれません。 3番目のオプション、 httpd.conf の Apache SetEnv ディレクティブは、一部のシステムでは 動作するかもしれませんが、他のシステムでは不適切であることが知られています。
環境変数が正しく設定されたかチェックするには、 phpinfo() を使って Environment セクション (Apache Environment ではありません) に期待される変数が含まれるかどうかチェックしてください。
必要かもしれない変数が下記の表に含まれます。 変数の全てについての詳細は Oracle ドキュメントを参照してください。
名前 | 目的 |
---|---|
ORACLE_HOME | Contains the directory of the full Oracle Database software. Do not set this when using Oracle Instant Client as it is unnecessary and may cause installation problems. |
ORACLE_SID | Contains the name of the database on the local machine to be connected to. There is no need to set this if you using Oracle Instant Client, or always pass the connection parameter to oci_connect(). |
LD_LIBRARY_PATH | Set this (or its platform equivalent, such as DYLD_LIBRARY_PATH, LIBPATH, or SHLIB_PATH) to the location of the Oracle libraries, for example $ORACLE_HOME/lib or /usr/lib/oracle/11.1/client/lib. This variable is not needed if the libraries are located by a different search mechanism, such as with ldconfig or with LD_PRELOAD. |
NLS_LANG | これは Oracle ライブラリで使用される文字セットや 国際化情報を設定するためのプライマリ変数です。 |
ORA_SDTZ | Sets the Oracle session timezone. |
TNS_ADMIN | Contains the directory where the Oracle Net Services configuration files such as tnsnames.ora and sqlnet.ora are kept. Not needed if the oci_connect() connection string uses the Easy Connect naming syntax such as localhost/XE. Not needed if the network configuration files are in one of the default locations such as $ORACLE_HOME/network/admin or /etc. |
OCI8 をインストールする際に最も一般的な問題は、 Oracle 環境が 正しく設定されないことです。通常、これは oci_connect() や oci_pconnect() 使用上の問題として現れます。 このエラーは Call to undefined function oci_connect() のような PHP エラーや、 ORA-12705 のような Oracle エラー、さらには Apache のクラッシュになるかもしれません。 この問題を解決するために、起動時のエラーについて Apache のログファイルをチェックして、 上記のセクションをご覧下さい。
While network errors like ORA-12154 or ORA-12514 indicate an Oracle network naming or configuration issue, the root cause may be because the PHP environment is incorrectly set up and Oracle libraries are unable to locate the tnsnames.ora configuration file.
On Windows, having multiple versions of Oracle on the one machine can easily cause library clashes unless care is taken to make sure PHP only uses the correct version of Oracle.
A utility to examine what libraries are being looked for and loaded can help resolve missing or clashing library issues, particularly on Windows.
注意: If the web server doesn't start or crashes at startup
Check that Apache is linked with the pthread library:
# ldd /www/apache/bin/httpd libpthread.so.0 => /lib/libpthread.so.0 (0x4001c000) libm.so.6 => /lib/libm.so.6 (0x4002f000) libcrypt.so.1 => /lib/libcrypt.so.1 (0x4004c000) libdl.so.2 => /lib/libdl.so.2 (0x4007a000) libc.so.6 => /lib/libc.so.6 (0x4007e000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
If the libpthread is not listed, then reinstall Apache:
# cd /usr/src/apache_1.3.xx # make clean # LIBS=-lpthread ./config.status # make # make install
Please note that on some systems like UnixWare, it is libthread instead of libpthread. PHP and Apache have to be configured with EXTRA_LIBS=-lthread.