LoginSignup
19
16

More than 5 years have passed since last update.

Macにoci8をインストールする

Last updated at Posted at 2013-05-02

環境

Mac OS X 10.8.3
Apache、PHP Mac標準のを使う(MAMPとかではない)
Oracle 11/g

pearインストール済み。(以下コマンドでインストール)

$ sudo php /usr/lib/php/install-pear-nozlib.phar

oci8がインストール済でも構わない(アンインストール方法も書いておきます)


1 Oracle Instant Clientをダウンロード

*ググると32bit版使えとか、64bit版だとsqlplusコマンド使えないとか出るけど、無視して64bit版の以下をダウンロードする。

instantclient-basic-macos.x64-11.2.0.3.0.zip
instantclient-sdk-macos.x64-11.2.0.3.0.zip
instantclient-sqlplus-macos.x64-11.2.0.3.0.zip

解凍

$ sudo mkdir /Library/Oracle
$ sudo unzip -d /Library/Oracle/ instantclient-basic-macos.x64-11.2.0.3.0.zip
$ sudo unzip -d /Library/Oracle/ instantclient-sdk-macos.x64-11.2.0.3.0.zip
$ sudo unzip -d /Library/Oracle/ instantclient-sqlplus-macos.x64-11.2.0.3.0.zip

2 設定

$ sudo vim ~/.bash_profile

パス通す為に.bash_profileに以下を設定する。

export ORACLE_HOME=/Library/Oracle/instantclient_11_2
export DYLD_LIBRARY_PATH=/Library/Oracle/instantclient_11_2
export PATH=$PATH:$DYLD_LIBRARY_PATH

export SQL_PATH=$ORACLE_HOME
#export ORACLE_SID=XE
export PATH=$PATH:$ORACLE_HOME
export NLS_LANG=Japanese_Japan.AL32UTF8
#export TNS_ADMIN=$ORACLE_HOME/network/admin/tnsnames.ora

反映

$ source ~/.bash_profile

libファイルのリンク作成

$ sudo ln -s /Library/Oracle/instantclient_11_2/libclntsh.dylib.11.1 /Library/Oracle/instantclient_11_2/libclntsh.dylib

3 oci8インストール

既にインストール済みなら以下のコマンドでアンインストールする。

$ sudo pecl uninstall oci8

*アンインストール後は関連ディレクトリを削除する必要があるので、削除するかリネームする(詳細は下の方に書いておきます)

インストール

$ sudo pecl install oci8

途中で以下のメッセージが出る

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] :

で、以下を入力してエンター

instantclient,/Library/Oracle/instantclient_11_2

以下が出ればインストールは正常終了。

Build process completed successfully
Installing '/usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so'
install ok: channel://pecl.php.net/oci8-1.4.9
configuration option "php_ini" is not set to php.ini location
You should add "extension=oci8.so" to php.ini

4 確認

$ php --ri oci8

以下みたいな感じで表示されればOK.

OCI8 Support => enabled
Version => 1.4.9
Revision => $Id: e2241cffb72c940cb2ca267b6a3b0ce436de2e3e $
Active Persistent Connections => 0
Active Connections => 0
Oracle Run-time Client Library Version => 11.2.0.3.0
Oracle Instant Client Version => 11.2
Temporary Lob support => enabled
Collections support => enabled

Directive => Local Value => Master Value
oci8.max_persistent => -1 => -1
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
oci8.default_prefetch => 100 => 100
oci8.old_oci_close_semantics => Off => Off
oci8.connection_class => no value => no value
oci8.events => Off => Off

apache再起動

$ sudo apachectl restart

ブラウザでinfo.phpへアクセスし、oci8でページ内検索してHitするのを確認。

おしまい…。


で、「oci8」がHitしない場合。

$ sudo vim /private/var/log/apache2/error_log

エラーログの内容を確認する。

多分、以下の様なエラーが出てる筈。

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so, 9): Library not loaded: /ade/b/2649109290/oracle/rdbms/lib/libclntsh.dylib.11.1\n Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so\n Reason: image not found in Unknown on line 0

もし、上記のエラーでなく以下の様なエラーが出てる場合は、oci8を再インストールする。

dyld: lazy symbol binding failed: Symbol not found: _OCIEnvNlsCreate
Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so
Expected in: flat namespace

dyld: Symbol not found: _OCIEnvNlsCreate
Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20090626/oci8.so
Expected in: flat namespace

再インストール時には、oci8インストール前に以下のディレクトリを削除するかリネームしておく。.bash_profileの値はそのままでいい。

$ cd /Library/Oracle/
$ sudo mv instantclient_11_2/ _instantclient_11_2_OLD/

念の為、oci8.soに実行権限を付加

$ cd /usr/lib/php/extensions/no-debug-non-zts-20090626/
$ sudo chmod +x oci8.so

4 launchd.confの設定

参考URL:
http://qiita.com/items/bb6a03538d4ee773c9b6

$ sudo vim /etc/launchd.conf

以下を記入して保存。

/etc/launchd.conf
setenv ORACLE_HOME /Library/Oracle/instantclient_11_2
setenv DYLD_LIBRARY_PATH /Library/Oracle/instantclient_11_2
setenv TNS_ADMIN $ORACLE_HOME/network/admin/tnsnames.ora
setenv ORACLE_SID XE

PCを再起動。

info.phpにアクセスし、oci8が表示される。

19
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
16