Quantcast
Channel: Coffeewithcode.com
Viewing all articles
Browse latest Browse all 40

How to install Oracle libraries for PHP5 on Ubuntu Server

$
0
0

An easy way to Connect Apache server (PHP) with Oracle database.

Execute following command in terminal to complete installation of oracle OCI8 extension in php.ini.

1) Get Oracle repository from this link.

     http://oss.oracle.com/debian unstable main non-free

2) 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 -

3) Get all the packages for PHP5, Oracle, and Apache2 server.

       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

4) Install Oracle OCI8 library.

       pecl install oci8

5) This will ask for your home directory. At the time of installing the Oracle client was installed in following path :

     /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/

6) 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

7) Restart Apache2 server.

    /etc/init.d/apache2 restart

 

 

Now make a simple test to find oracle connectivity with php.

Make test.php and paste following  code.

  1. <?php
  2. //oracle connection variables
  3. $ora_user = 'USER_NAME'; //username
  4. $ora_pass = 'PASSWORD'; //password
  5. $ora_host = 'SERVER_IP_OF_ORACLE"'; //host name or server ip address
  6. $ora_db = ‘DATABASE_NAME'; //database name
  7.  
  8. $conn = oci_connect($ora_user,$ora_pass,'//'.$ora_host.'/'.$ora_db);
  9.  
  10. // error handling
  11. if (!ora_conn){ // if variable $conn fails to connect
  12. // do the following if it fails
  13. $ora_conn_erno = oci_error(); // insert oci_error() function into variable
  14. echo ($ora_conn_erno['message']."\n"); // print the $ora_conn_erno variable/oci_error() function selecting only the message (human readable)
  15. oci_close($conn); // close the connection just in case php doesn't close it
  16. } else {
  17. // if it doesn't fail it will proceed with the rest of the script
  18. echo "Connection Successful\n"; //echo message if connection does not error
  19. oci_close($conn); // close the connection
  20. }
  21. ?>

Viewing all articles
Browse latest Browse all 40

Trending Articles