Installing Oracle Instant Client on Redhat Linux and PHP OCI Extension
Problem Description :
Details how to configure PHP on Redhat to connect to a remote Oracle Database. This uses the Oracle Instant Client for Linux. OCI8 is the PHP extension for connecting to Oracle Databases
Resolution :
Before you begin make sure that SELinux is set to Permissive mode. The defaul mode is Enforcing on RHEL 5. SQL*Plus and OCI program calls will fail when set to the default mode.
Make sure you have the following packages in Redhat installed (specifically the pear framework for PHP which will allow you to download the OCI8 extension)
1. Download the Instant Client (Basic and SDK) for Linux x86-64 at http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html. Click on the RPM versions. Place someplace on the Redhat server.
oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
2. CD to the folder you installed the RPMs for the Instant Client in. Install the RPM as the root user using the following commands from a terminal window.
rpm -Uvh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
rpm -Uvh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
The first RPM puts Oracle libraries in /usr/lib/oracle/11.2/client64/lib and the second creates headers in /usr/include/oracle/11.2/client64.
3. The latest version of the OCI8 PHP extension can be automatically downloaded using the command below (must have the PHP-PEAR package installed).
pecl install oci8
This gives:
downloading oci8-1.4.7.tgz ...
Starting to download oci8-1.4.7.tgz (Unknown size)
.....done: 168,584 bytes
10 source files, building
running: phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
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] :
If you have the Instant Client RPMs, hit Enter and PECL will automatically build and install an oci8.so shared library. If you have the Instant Client zip files, or want a specific version of Instant Client used, then explicitly give the appropriate path after "instantclient,":
instantclient,/usr/lib/oracle/11.2/client64/lib
Use an explicit, absolute path since PECL does not expand environment variables.
4. Once the install for the oci8 shared library completes, open the php.ini file located under /etc/ in a text editor. Find the section under Dynamic Extensions and enable the oci8 extension with...
extension=oci8.so
* If there is an error make sure you have the gcc package installed to compile C programs *
5. Navigate to the httpd service configuration file found under /etc/sysconfig/. At the bottom of the file manually add the location of the oracle instant client library with..
LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
Save the file
You can add environment variables here for TNS_ADMIN and NLS_LANG as well however I did not have to do this for our installation.
6. Save a complete tnsnames.ora file under the /etc/ directory. This can be copied from another server. This is the default location that the Oracle Instant Client uses. If you save it in another location you willl have to create an environment variable following step #5 above.
7. To prevent SELinux warnings when web visitors access applications connected to Oracle - open the SELinux Management tool in Redhat and select Boolean. Make sure that the option 'Allow HTTPD scripts and modules to connect to the network' is selected.
8. Restart Apache
9. For verifying the PHP OCI8 Extension is installed, create a simple PHP script phpinfo.php in the Apache document root: /var/www/html
<?php
phpinfo();
?>
Load the script into a browser. The phpinfo page will contain an "oci8" section saying "OCI8 Support enabled" and will list the OCI8 options that can be configured. Delete the file for security purposes.
Revision Date : 11/8/2012