[Gena01 Logo]
October 11, 2008, 07:44:39 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Tags Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Installing Oracle Instant Client and making it work with PHP  (Read 5780 times)
0 Members and 1 Guest are viewing this topic.
Gena01
Administrator
Sr. Member
*****
Posts: 393



View Profile WWW
« on: October 31, 2007, 01:27:35 PM »
Reply with quoteQuote

This is something that I wanted to post up for a while, because this is rather simple stuff and yet it took me a while to put this whole thing together for my own use/setup. It's also something that got some people interested and they asked me to post this up. So this post is for Maggie Nelson who is an active PHP and Oracle advocate.

These instructions are for Linux since this is what I use. I am also using Mandriva 2007.1 and will be using RPM packages where available and will mentioned some things specific to Mandriva.

Setup consists of two parts:
1. Installing Oracle Instant Client on Linux
2. Getting and compiling oci8 extension for PHP.

So let's begin.

Installing Oracle Instant Client on Linux:

1. Download the Oracle Instant Client for Linux rpms from http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html. The files that I am using and that you will need are:
Code:
      oracle-instantclient-sqlplus-10.2.0.3-1
      oracle-instantclient-devel-10.2.0.3-1
      oracle-instantclient-basic-10.2.0.3-1
2. Install those rpms to your linux system:
Code:
sudo rpm -ivh oracle-instantclient-*
NOTE: Here is where things get interesting. We need to prepare a couple of configuration files and you will need to become root in order to make those files usable on a global level.
3. You need to be root at this point:
Code:
sudo bash
4. Create /etc/oracle directory as this is where we will store Oracle configuration files.
5. You will also need to grab a copy of tnsnames.ora file either from your Oracle DBA or from another system.
Code:
copy tnsnames.ora /etc/oracle
6. Create a shell script that will initialize Oracle environment variables.
Code:
vi /etc/profile.d/oracle.sh
place the following into that file:
Code:

    export TNS_ADMIN=/etc/oracle/
    export SQLPATH=/usr/lib/oracle/10.2.0.3/client/bin
    export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client/lib:$LD_LIBRARY_PATH
    export PATH=$PATH:$SQLPATH
7. This is pretty much it. When you logout and log back in you should confirm that your environment variables are there using
Code:
export
. Also try out sqlplus to make sure it works and can connect to your Oracle database.

Getting and compiling oci8 extension for PHP:
1. pear download pecl/oci8
2. tar -xzvf oci8-1.2.4.tgz
3. cd oci8-1.2.4
4. phpize  (php4ize for php4 support, it seems Mandriva names these binaries differently for php4)
5. ./configure --with-oci8=instantclient,/usr/lib/oracle/10.2.0.3/client/lib
6. make
7. sudo make install
Now become root user (sudo bash)
8. Create a file called /etc/php.d/999_oci.ini and place the following line there:
Code:
      extension=oci8.so
9. vi /etc/sysconfig/http and add the following lines at the very end of the file
Code:
      ###
      #
      # Adding ORACLE Variables to the config status (cause during upgrade the httpd file got replaced :( )
      #
      export TNS_ADMIN=/etc/oracle
      export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
10. service httpd restart
11. And you are done. Pull up a page that calls phpinfo() and confirm that oci8 is loaded in apache and that the environment variables are setup properly. You can also do "php -m" to see of php cli loads the module as well.

I hope that this is very informative and that I didn't miss anything. If there's something that I missed or there's an error somewhere then please let me know and I will correct it.

UPDATE: Make sure you have php "dev" package installed so that you can compile PHP extension(s).
UPDATE 2: I have posted updated instructions regarding Oracle Instant Client 11g and building Pecl OCI8 with 1 line

Gena01
« Last Edit: January 04, 2008, 11:42:05 AM by Gena01 » Report to moderator   Logged
Tags: Oracle Instant Client PHP Pecl 
Pages: [1]
  Reply  |  Print  
 
Jump to:  

BoldItalicizedUnderlineStrikethrough|Preformatted TextLeft AlignCenteredRight Align|Horizontal Rule|Font SizeFont Face
Insert ImageInsert HyperlinkInsert Email|SuperscriptSubscriptTeletype|Insert CodeInsert Quote|Insert List
Smiley Wink Cheesy Grin Angry Sad Shocked Cool Huh Roll Eyes Tongue Embarrassed Lips sealed Undecided Kiss Cry
Powered by MySQL Powered by PHP Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.042 seconds with 17 queries.