[Gena01 Logo]
November 23, 2024, 10:19:00 pm *
Welcome, Guest. Please login or register.

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



WWW
« on: October 31, 2007, 12:27:35 pm »

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 (http://www.objectivelyoriented.com/) 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 (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 (http://www.gena01.com/forum/gena01_blog/installing_oracle_instant_client_11g_and_pecl_oci8-t193.0.html)

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

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines | Sitemap Valid XHTML 1.0! Valid CSS!