phporacle-databaseapacheslackware

Page not displaying with apache and php and OCI8 and Oracle Express 11g


I have Oracle Express 11g installed on Slackware linux and running. I am able to connect to it and run queries. I have apache and php installed and oci8 installed. phpinfo() is showing oci8 loaded and enabled. For the following simple php script the web page displays:

<?php echo "Hello World!!!"; ?>

So php in apache is working. Now for the following simple connect to oracle and show the version:

<html>
<body>
Oracle Version <br/>
<?php

$conn = oci_connect('SYSTEM', 'password', 'localhost/XE');

$stid = oci_parse($conn, 'select banner from v$version');
oci_execute($stid);

echo "<table>\n";
while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "  <td>".($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;")."</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";

?>
</body>
</html>

This is showing the following from view source in web browser:

<html>
<body>
Oracle Version <br/>
<table>
</table>
</body>
</html>

However when I run the script with /usr/bin/php oratest.php it outputs the following correctly:

<html>
<body>
Oracle Version <br/>
<table>
<tr>
  <td>Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production</td>
</tr>
<tr>
  <td>PL/SQL Release 11.2.0.2.0 - Production</td>
</tr>
<tr>
  <td>CORE      11.2.0.2.0      Production</td>
</tr>
<tr>
  <td>TNS for Linux: Version 11.2.0.2.0 - Production</td>
</tr>
<tr>
  <td>NLSRTL Version 11.2.0.2.0 - Production</td>
</tr>
</table>
</body>
</html>

How is this possible. Why would command line php work and apache serving up the same php script doesnt work. And phpinfo() served up by same apache is showing oci8 installed and enabled.

Please help if you have any ideas thanks in advance.


Solution

  • The errors were occurring due to the ORACLE_HOME and LD_LIBRARY_PATH not being set correctly for the oracle instant client and oracle express 11g etc installation paths. I used putenv() php directive at start of php code and it worked with no errors.

    putenv("ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe");
    putenv("LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/xe/lib:/usr/lib64/oracle/12.1/client64/lib");