The other day I had the need to communicate with an Oracle Database server remotely. Looking online took me to a few sources and forum threads before I actually had a 100% complete installation working. Hopefully this will serve as a complete resource for installing and configuring what is needed to get the OCI libraries working with PHP5.
Begin by adding the Oracle repository to your source list:
deb http://oss.oracle.com/debian unstable main non-free
You need to make sure to add the proper GPG key for the repository:
sudo wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle -O- | sudo apt-key add -
Get all the packages for PHP5, Oracle, and Apache2:
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install php5-dev
sudo apt-get install php5
sudo apt-get install php-pear
sudo apt-get install oracle-xe-client
sudo apt-get install apache2
sudo apt-get install libapache2-mod-php5
Execute the command to install the Oracle OCI8 library:
pecl install oci8
This will ask for your home directory. At the time of installing the Oracle client was dropped in:
/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/
When the installation is complete you will need to add the extension information to both instance of php.ini:
echo "extension=oci8.so" >> /etc/php5/cli/php.ini
echo "extension=oci8.so" >> /etc/php5/apache2/php.ini
Restart Apache2:
/etc/init.d/apache2 restart
Create a page to test the connection:
<?php
//oracle connection variables
$ora_user = 'YOUR_USERNAME'; //username
$ora_pass = 'YOUR_PASS'; //user password
$ora_host = 'SERVER_IP_OF_ORACLE"'; //host name or server ip address
$ora_db = 'YOUR_DATABASE'; //database name
// place variable into oci_connect function, then place funtion in variable
$ora_conn = oci_connect($ora_user,$ora_pass,'//'.$ora_host.'/'.$ora_db);
// error handling
if (!ora_conn){ // if variable $ora_conn fails to connect
// do the following if it fails
$ora_conn_erno = oci_error(); // insert oci_error() function into variable
echo ($ora_conn_erno['message']."\n"); // print the $ora_conn_erno variable/oci_error() function selecting only the message (human readable)
oci_close($ora_conn); // close the connection just in case php doesn't close it
} else {
// if it doesn't fail it will proceed with the rest of the script
echo "Connection Succesful\n"; //echo message if connection does not error
oci_close($ora_conn); // close the connection
}
?>
Surf to the page to see if it executes the connection.
Comments
Problem with activation
Sat, 05/22/2010 - 17:52 — AnonymousHi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... http://www.dueyesterday.net/?f84c2f1a46c1706579fe4199ac5,