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:
1 |
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:
1 |
;extension=php_oci8.dll |
Change it to:
1 |
extension=php_oci8.dll |
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:
1 |
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 11.2.0.4.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-11.2.0.4.0.zip
- SQLplus: instantclient-sqlplus-macos.x64-11.2.0.4.0.zip
- SDK: instantclient-sdk-macos.x64-11.2.0.4.0.zip
- Once you have downloaded all 3 packages, open up terminal.
- Switch to root and create a working directory:
1234sudo sucd /tmpmkdir ocicd oci - Move the downloaded packages to your working directory ([DOWNLOAD LOCATION] = your download location):
123mv [DOWNLOAD LOCATION]/instantclient-basic-macos.x64-11.2.0.4.0.zip /tmp/oci/mv [DOWNLOAD LOCATION]/instantclient-sqlplus-macos.x64-11.2.0.4.0.zip /tmp/oci/mv [DOWNLOAD LOCATION]/instantclient-sdk-macos.x64-11.2.0.4.0.zip /tmp/oci/ - Extract:
1234cd /tmp/ociunzip instantclient-basic-macos.x64-11.2.0.4.0.zipunzip instantclient-sdk-macos.x64-11.2.0.4.0.zipunzip instantclient-sqlplus-macos.x64-11.2.0.4.0.zip - Copy the necessary files into your OS X dynamic library and bin directories:
1234cp /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:
12cd /usr/libln -s libclntsh.dylib.11.1 libclntsh.dylib - Test SQLplus:
1/usr/bin/sqlplus
Should output:
123SQL*Plus: Release 11.2.0.4.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:
1pear version
If its installed, you should get the following output or similar:
1234PEAR 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:
123cd /tmp/ocisudo pecl channel-update pecl.php.netsudo pecl install oci8 - During the install, you will be prompted:
1Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :
Enter:
1instantclient,/usr/lib - Once the install is complete, open your php.ini file and add the following to the end of the file:
1extension=oci8.so - 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.
1apachectl restart
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.