Installing PHP/11g Instant Client/OCI8 1.3.0 on Oracle Enterprise Linux
Posted at Friday, October 12, 2007
Here are the steps for setting up an Oracle Enterprise Linux distribution
for Oracle/PHP development, using the latest Oracle Instant Client and OCI8 distributions.
I chose this combination, because the new version of OCI is reported to support Oracle's new Database Resident Connection Pooling (DCRP) functionality. This will help PHP shops that use Oracle scale more effectively.
I integrated the following software with my server's existing Apache installation:
Here is software I used:
First, I installed the instant client packages:
This will install the 11g Instant Client into /usr/lib/oracle/11.1.0.1.
Next, I unpack php and oci in preparation to build and make:
Since I am installing a newer version of OCI than
that which comes natively with php, I will need to delete the oci8 directory under the php software and replace it with the aforemetioned beta release:
Afterwards, I will rebuild the configuration, configure, make, and then make install:
Now there should be a libphp5.so shared object in /etc/httpd/modules. The next step is to configure Apache for php as well as for Oracle database connectivity. I followed the following steps:
Stop Oracle from loading old PHP libraries
Add appropriate directives to httpd.conf:
Put the php.ini into place and edit as appropriate
Decide on a location for TNS_ADMIN and place an appropriately edited tnsnames.ora file there:
Update apachectl with the appropriate Oracle-centric variables
Now I start Apache so that I can perform my verification tests
Create the following 2 files in the web root (for me /var/www/html):
info.php
oraconnect.php
Now I test the pages. The call to http://rac2.colestock.test/info.php should reflect all the appropriate values, including the environment variables we set in apachectl as well as the correct oci8 version, etc.
The call to http://rac2.colestock.test/oraconnect.php should return the results from the user_tables view.
for Oracle/PHP development, using the latest Oracle Instant Client and OCI8 distributions.
I chose this combination, because the new version of OCI is reported to support Oracle's new Database Resident Connection Pooling (DCRP) functionality. This will help PHP shops that use Oracle scale more effectively.
I integrated the following software with my server's existing Apache installation:
# apachectl -v
Server version: Apache/2.0.52
Here is software I used:
- Download oracle-instantclient-basic-11.1.0.1-1.i386.rpm and oracle-instantclient-devel-11.1.0.1-1.i386.rpm
- Download php-5.2.4.tar.gz
- Download oci8-1.3.0.tgz (OCI8 1.3.0-beta)
First, I installed the instant client packages:
# rpm -Uvh oracle-instantclient-basic-11.1.0.1-1.i386.rpm
# rpm -Uvh oracle-instantclient-devel-11.1.0.1-1.i386.rpm
This will install the 11g Instant Client into /usr/lib/oracle/11.1.0.1.
Next, I unpack php and oci in preparation to build and make:
# gunzip php-5.2.4.tar.gz
# tar -xvf php-5.2.4.tar
# gunzip oci8-1.3.0.tgz
# tar -xvf oci8-1.3.0.tar
Since I am installing a newer version of OCI than
that which comes natively with php, I will need to delete the oci8 directory under the php software and replace it with the aforemetioned beta release:
# cd /u03/php-5.2.4/ext
# rm -Rf oci8
# mkdir oci8
# cd ../../oci8-1.3.0
# cp -R * /u03/php-5.2.4/ext/oci8/
Afterwards, I will rebuild the configuration, configure, make, and then make install:
# cd /u03/php-5.2.4
# ./buildconf --force
# ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.1.0.1/client/lib --prefix=/var/www/php --with-apxs2=/usr/sbin/apxs --enable-sigchild --with-config-file-path=/var/www/php
# make
# make install
Now there should be a libphp5.so shared object in /etc/httpd/modules. The next step is to configure Apache for php as well as for Oracle database connectivity. I followed the following steps:
Stop Oracle from loading old PHP libraries
# cd /etc/httpd/modules
# mv libphp4.so libphp4.so.old
# cd /etc/httpd/conf.d
# mv php.conf php.conf.old
Add appropriate directives to httpd.conf:
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
AddType application/x-httpd-source .phps
Put the php.ini into place and edit as appropriate
# pwd
/var/www/php
# more php.ini
display_errors = on
error_reporting = E_ALL & ~E_NOTICE
extension=oci8.so
oci.events=on
Decide on a location for TNS_ADMIN and place an appropriately edited tnsnames.ora file there:
# pwd
/usr/lib/oracle/11.1.0.1/client
# more tnsnames.ora
NF =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2.colestock.test)(PORT = 1523))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = nf.colestock.test)
)
)
Update apachectl with the appropriate Oracle-centric variables
TNS_ADMIN=/usr/lib/oracle/11.1.0.1/client; export TNS_ADMIN
LD_LIBRARY_PATH=/usr/lib/oracle/11.1.0.1/client/lib; export LD_LIBRARY_PATH
Now I start Apache so that I can perform my verification tests
# apachectl start
Create the following 2 files in the web root (for me /var/www/html):
info.php
<?php
phpinfo();
?>
oraconnect.php
<?php
$conn = OCILogon("scott", "tiger", 'NF');
$query = 'select table_name from user_tables';
$stid = OCIParse($conn, $query);
OCIExecute($stid, OCI_DEFAULT);
while ($succ = OCIFetchInto($stid, $row)) {
foreach ($row as $item) {
echo $item." ";
}
echo "<br>\n";
}
OCILogoff($conn);
?>
Now I test the pages. The call to http://rac2.colestock.test/info.php should reflect all the appropriate values, including the environment variables we set in apachectl as well as the correct oci8 version, etc.
The call to http://rac2.colestock.test/oraconnect.php should return the results from the user_tables view.
Labels: Installation, Instant Client, OCI, PHP
