I'm trying to set up a server for a project in my databases class. I'll be writing the project in php, deploying it via apache, and connecting to a remote oracle server. I'm having trouble with the oracle connection portion. I have the OCI8 module installed with oracle's instantclient version 10.2. I thought it was working because when I ran the following program from the console I got the right output.
Program:
<?php
$conn = oci_connect("asdf", "asdf", "asdf");
if (!$conn) {
die("connection error\n");
}
$stid = oci_parse($conn, 'SELECT * FROM PARTS');
if (!$stid) {
die("statement parsing error\n");
}
$r = oci_execute($stid);
if (!$r) {
die("execution error\n");
}
print "<table border='1'\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
print "<tr>\n";
foreach ($row as $item) {
print "\t<td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
print "</tr>\n";
}
print "</table>\n";
oci_free_statement($stid);
oci_close($conn);
?>
Result:
<table border='1'>
<tr>
<td>1</td>
<td>wrench</td>
<td>silver</td>
</tr>
<tr>
<td>2</td>
<td>hammer</td>
<td>brown</td>
</tr>
</table>
So I thought everything was fine. But when I visit the same php page in a browser I get the following error message:
Fatal error: Call to undefined function oci_connect() in /home/eric/apache2/htdocs/realestate/basicQuery.php on line 2
I thought that might mean that two different versions of php were getting used for the command line and in apache, so I ran phpinfo(); for both. But they both came back with the same php info (PHP Version 5.2.10-2ubuntu6.4). They are using different php.ini files (/etc/php5/apache2/php.ini and /etc/php5/cli/php.ini), but they both are exactly the same. I don't know where else to look for anything that might be different in one environment versus the other.
Thanks for any help!
Did you have the oci8 extension installed in your system? Check that if it is not then to install it follow the below links?
For understanding refer this. Installing oci8 extension in linux for php?
For clear instruction to install refer this link. http://www.oracle.com/technetwork/articles/dsl/technote-php-instant-12c-2088811.html
Check your php.ini file whether you have the following things set.
After the installation you should restart apache. Let me know if this helps you.
This can be a lot of stuff, the OCI8 module isn't installed properly, isn't loaded by apache or even a dependency isn't installed.
Installing OCI8
The easiest way to install OCI8 is using pecl:
pecl install oci8-2.0.12 # for PHP 5.5/6
Enabling module
Then you need to load it by placing the
extension=oci8.so
in yourphp.ini
.Now make sure that there is a
oci8.so
file in yourextension_dir
configuration. This can be found in phpinfo or executingphp -i | grep extension_dir
. For example, mine is/usr/lib/php/20131226
.Restart your apache executing
apachectl restart
and see if there is aoci8
configuration in your phpinfo.The mercy shot
If you tried everything and it didn't work (that already happened to me), make sure
libaio1
is installed in your system. If it isn't, install it by executingapt install libaio1
and restart your apache. In my case, it did the trick. Hope that helps.PHP needs to know where to load its extension from (this bridges between PHP and the Oracle supplied libs). Since its working from the CLI you seem to have got the package installed.
If the ini files are the same, then you also need to check:
1) did you remember to restart apache after configuring the oracle libs?
2) does your webserver run as chroot?
3) what are the permissions on the oci8 extension? (i.e. is it readable by the webserver uid)
You also need to add the path to the oracle .so files to your ld.so.conf and run ldd or tweak your Env vars - but this will give a different error to the one you describe if you skip it.
HTH
C.