I have been using PHP with Oracle DB for sometime now, but recently after upgrading to Mac OS X 10.9, i’ve had to re-install the PHP library and reconfigure it. After many failed attempts to install OCI8, i have finally managed to get it working and thought i would share my findings.
Before i start, i do know of other issues related to OCI which may help get it running without reconfiguring PHP.
If you get the following error while trying to use oracle with PHP:
Fatal error: Call to undefined function oci_connect()
It could either mean that OCI8 is not enable or is not installed. To fix this, open your php.ini file and find the line:
Change it to:
Run your php script and check if it works. If it does not work, it means that you do not have OCI8 installed and configured for PHP and you are probably seeing the following error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20100525/php_oci8.dll
Install and configure OCI8 with PHP:
- Download the following Oracle client library files from ORACLE, making sure you download Version 22.214.171.124.0 (64-bit). You will need to have an Oracle user account and logged in to download the required files. If you do not have an account, create one, its free.
- Basic: instantclient-basic-macos.x64-126.96.36.199.0.zip
- SQLplus: instantclient-sqlplus-macos.x64-188.8.131.52.0.zip
- SDK: instantclient-sdk-macos.x64-184.108.40.206.0.zip
- Once you have downloaded all 3 packages, open up terminal.
- Switch to root and create a working directory:
Shell1234sudo sucd /tmpmkdir ocicd oci
- Move the downloaded packages to your working directory ([DOWNLOAD LOCATION] = your download location):
Shell123mv [DOWNLOAD LOCATION]/instantclient-basic-macos.x64-220.127.116.11.0.zip /tmp/oci/mv [DOWNLOAD LOCATION]/instantclient-sqlplus-macos.x64-18.104.22.168.0.zip /tmp/oci/mv [DOWNLOAD LOCATION]/instantclient-sdk-macos.x64-22.214.171.124.0.zip /tmp/oci/
Shell1234cd /tmp/ociunzip instantclient-basic-macos.x64-126.96.36.199.0.zipunzip instantclient-sdk-macos.x64-188.8.131.52.0.zipunzip instantclient-sqlplus-macos.x64-184.108.40.206.0.zip
- Copy the necessary files into your OS X dynamic library and bin directories:
Shell1234cp /tmp/oci/instantclient_11_2/sdk/include/*.h /usr/includecp /tmp/oci/instantclient_11_2/sqlplus /usr/bincp /tmp/oci/instantclient_11_2/*.dylib /usr/libcp /tmp/oci/instantclient_11_2/*.dylib.* /usr/lib
- Add symbolic links required for setup:
Shell12cd /usr/libln -s libclntsh.dylib.11.1 libclntsh.dylib
- Test SQLplus:
Shell123SQL*Plus: Release 220.127.116.11.0 Production on Thu Jun 19 14:31:23 2014Copyright (c) 1982, 2013, Oracle. All rights reserved.
Press CTRL+C to quit SQLplus.
- The Oracle client should now be installed correctly and we can start installing OCI8.
- Check that you have PEAR installed:
If its installed, you should get the following output or similar:
Shell1234PEAR Version: 1.9.4PHP Version: 5.4.24Zend Engine Version: 2.4.0Running on: Darwin 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014;
If not, you will need to install PEAR in order to continue.
- Download and Install OCI8 PECL package:
Shell123cd /tmp/ocisudo pecl channel-update pecl.php.netsudo pecl install oci8
- During the install, you will be prompted:
Shell1Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :
- Once the install is complete, open your php.ini file and add the following to the end of the file:
- Now all you need to do is restart apache and test your PHP script again. You can also check that OCI8 is installed running “php -i | grep oci” in terminal and check the output.
Thats it. If you do not have pear installed or cant get it installed, then you will need to install OCI8 manually by downloading OCI8 from PECL and compiling it with PHP 5.4.