Php – How to set up OCI to connect to Oracle from PHP

oracleoracle-call-interfacePHP

On the latest Ubuntu, I have a functioning PHP 5.2.4 installation. I want to use a remote Oracle server from PHP using OCI.

I've downloaded the "Instant Client Package – Basic Lite" (Link). I've unzipped the package containing the OCI libraries to a dir but I have no idea how to tell PHP that I want to use these libraries. Predictably, I get

Fatal error: Call to undefined function oci_connect() in…

when running this code:

<?php 
   $conn = oci_connect('hr', 'hrpw', 'someremotehost');
?>

I don't want to recompile PHP with Oracle support. What's the fastest way to wire up PHP so that I can use Oracle? Do I need any other libaries, like the Oracle client if I want to connect to a remote Oracle instance?

Best Answer

You need the PHP extension, try the following on your Ubuntu:

(sudo) pecl install oci8

Make sure your php.ini's (there should be one for your Apache and one for cli php) contain extension=oci8.so afterwards. Finally, you have to restart Apache and can confirm via <?php phpinfo(); ?> that the extension is loaded.

UPDATE:

Enter something like this when it asks you for ORACLE_HOME:

instantclient,/opt/oracle/instantclient

I think setting the environment variable would be another solution. /opt/oracle... is the path I put my instantclient in. I followed some tutorial a while ago, unfortunately I can't find it anmore.

HTH