Reply to comment

RedHat 5 + PHP 5 + oci8 + Oracle 7


So, today I faced a new challenge at work. Yesterday we updated one of our linux boxes from RedHat 3 to RedHat 5. The server was hosting a web application that takes data both from a mysql database (for content management) and oracle 7.3 (for corporative data).

The access from php to Oracle 7.3 was being done with a php module called oci 8 (http://es.php.net/oci8) that relied on an oracle client being properly installed on the machine.

While we were using RedHat 3 there was no issue at all, the oci8 rpm that was installed came from pbone and was working fine, as it was apparently compiled against a v8 or v9 Oracle client, but, after upgrading, we found out that the new version of that rpm was compiled against a v10 oracle client. This was an issue, as the last client supporting connections to Oracle 7.3 was 9.0.1. In other words, the web application was not able to log in to oracle anymore.

To get the web application to connect back to Oracle I needed to perform the following steps:
1. Get the latest php oci8 (from http://es.php.net/oci8)

$> tar zxvf oci8-1.2.4.tgz


2. Install the php-devel suite to have phpize and so (by issuing yum install php-devel)

$> yum install php-devel


3. Phpize the source code

$> cd oci8-1.2.4
$> phpize
$> ./configure
$> make

And here came the issues: the client we had for oracle 9.0.1 was not completely installed and I needed to reinstall it. Obviously, such an old installer version was not going to run on RedHat 5, so I decided to run the oracle client installer from a virtual machine running Centos 2.1.

I won't cover the installation of oracle 9.0.1 under Centos/redhat Enterprise 2.1 as it would need a few paragraph more, for the non-initiated, you can get some instructions from here

In order to be sure that I won't miss anything, I choose the Client option, and afterwards, marked everything available. It worked kinda flawlessly, until more or less the 62%, then it failed and I had to apply the instructiosn covered here to complete the installation.

When it reached 100%, I copied the resulting oracle client into the upgraded web server and tried the 3 previous steps. It failed again, now telling me that certain constant was not there. After a few searches I found out that I needed to patch php-oci8 source code as indicated here (http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2007-May/120308.html) to get it to compile with pre 9.2 versions. Seems that this is because the new code in php-oci8 relies in that variable, which exists on versions newer than 9.0.1

Here is the patch, just in case the archive of mails dissappears:

--- php5-oci8.orig/files/patch-oci8_lob.c Thu Jan 1 01:00:00 1970
+++ php5-oci8/files/patch-oci8_lob.c Tue May 22 12:34:09 2007
@@ -0,0 +1,20 @@
+--- oci8_lob.c.orig Thu Mar 29 11:33:03 2007
++++ oci8_lob.c Tue May 22 12:33:23 2007
+@@ -301,6 +301,7 @@
+ }
+
+ if (is_clob) {
++#ifdef OCI_NLS_CHARSET_MAXBYTESZ
+ PHP_OCI_CALL_RETURN(connection->errcode,
OCINlsNumericInfoGet, (connection->env, connection->err, &bytes_per_char, OCI_NLS_CHARSET_MAXBYTESZ));
+
+ if (connection->errcode != OCI_SUCCESS) {
+@@ -308,6 +309,9 @@
+ PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
+ return 1;
+ }
++#else
++ bytes_per_char = 4;
++#endif
+ } else {
+ /* BLOBs don't have encoding, so bytes_per_char == 1 */
+ }

After patching the code, I just had to do

$> make
$> cp modules/oci8.so /usr/lib/php/modules/
$> service httpd restart

It worked. Now we can connect to oracle 7.3 again from Php 5 ;)

This solution is great because it allows you to connect to old versions of oracle (7, 8, 8i, 9i) from php. In some corporate environments is really difficult to get all the databases updated to the latest version, and this kind of tools help you build systems that can get data from those databases while using modern languages and tools.

I have attached to this post the patched and php-ized oci8 1.2.4, I won't maintain it, it's just here for reference. Any question, just comment!

Reply

  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post PHP code. You should include <?php ?> tags.

More information about formatting options