19 April 2012

ติดตั้ง Oracle Client บน Ubuntu Server

ขออนุญาติ Copy ครับ จาก http://www.notewee.com/?p=336


ติดตั้ง Oracle Client บน Ubuntu 9.10 (Karmic Koala)
By Note, 17 February, 2010, No Comment

จุดประสงค์เพื่อที่จะเขียน PHP connect กับ Oracle Database ทั้งนี้ทั้งนั้นต้องติดตั้ง OCI8 ให้ได้ เพื่อเรียกใช้ function ต่าง ๆ ในการเชื่อมต่อ

ใน entry นี้จะกล่าวเฉพาะการติดตั้ง PHP5 จนถึงการติดตั้ง Oracle Client เท่านั้น
โดยมีชุดคำสั่งดังนี้

- จำลองตัวเป็น root ก่อน

    sudo –i

- ทำการ update ระบบ

    apt-get update
    apt-get upgrade

- ติดตั้ง PHP5 และ module ที่เกี่ยวข้อง

    apt-get install php5-common php5 php5-dev libapache2-mod-php5 php5-cli

- ติดตั้ง PHP-PEAR

    apt-get install build-essential php-pear

- ติดตั้ง module libaio1

    apt-get install libaio1

- สร้าง directory สำหรับ oracle

    mkdir -p /opt/oracle
    cd /opt/oracle

- Download Oracle client โดยเลือกตัวที่เป็น basic และ sdk จาก website http://www.oracle.com/technology/tech/oci/instantclient/index.html อย่าลืมสมัครเป็นสมาชิกก่อน

- ติดตั้ง unzip

    apt-get install unzip

- จัดการ unzip ไฟส์ที่ได้มา (ปัจจุบันจะได้ตัว client ตามนี้ เวลาใช้จริงอย่าลืมเปลี่ยนชื่อไฟส์ให้ตรงกับที่ Download มาด้วย

    unzip instantclient-basic-linux32-11.2.0.1.zip
    unzip instantclient-sdk-linux32-11.2.0.1.zip

- Unzip เรียบร้อย จะได้ directory ที่ชื่อ instantclient_11_2 (อาจเปลี่ยนได้ตาม Version ที่ Download) ให้เปลี่ยน directory เป็น instantclient

    mv instantclient_11_2 instantclient
    cd instantclient

- จัดการสร้าง link file

    echo /opt/oracle/instantclient >> /etc/ld.so.conf
    ldconfig
    ln -s libclntsh.so.11.1 libclntsh.so
    ln -s libocci.so.11.1 libocci.so

- สร้าง directory เตรียมสำหรับ oci8

    mkdir -p /opt/oracle/src
    cd /opt/oracle/src

- download oci8 จาก http://pecl.php.net/package/oci8

wget http://pecl.php.net/get/oci8-1.4.7.tgz

    tar xzf oci8-1.3.5.tgz

- ทำการติดตั้ง oci8

    cd oci8-1.3.5
    phpize
    ./configure –with-oci8=shared,instantclient,/opt/oracle/instantclient
    make
    make install

- แก้ไข php.ini โดยเพิ่ม extension=oci8.so  เข้าไป

    sudo nano /etc/php5/apache2/php.ini

- restart apache

    /etc/init.d/apache2 restart

อ้างอิง :

http://ubuntuforums.org/showthread.php?t=637158
http://ubuntuforums.org/showthread.php?t=92528

installing cx_oracle under ubuntu 10.10


If you plan on writing any python applications/scripts for performing any basic SQL query’s against an oracle database you will need to have the cx_oracle library files installed to your machine (or server) here are some quick instructions on how to install them.
Please be aware i have only tested these instructions under Ubuntu 10.10 (32bit) using the 11.2 oracle instant client, when I have time I will try and install this on one of the x86_64 machines i have access to.
1. become root user
1sudo su -
2. install python-setuptools python-dev needed for the easy_install later on.
1apt-get install python-setuptools python-dev
3. install the following from the oracle website http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
* instantclient-basic-linux (32bit or 64bit depending on your system)
* instantclient-sdk-linux (32bit or 64bit depending on your system)
I have installed the files to /opt/instantclient_11_2 for ease
3. Setup ORACLE_HOME and LD_LIBRARY_PATH e.g.
       mkdir /opt/instantclient_11_2

1export ORACLE_HOME=/opt/instantclient_11_2
2export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
4. The cx_oracle file needs to find a certain library file libclntsh.so you will find this under /opt/instantclient_11_2/libclntsh.so.X.X (X = version number) please make a symlink as follows
1cd $ORACLE_HOME
2ln -s libclntsh.so.11.1 libclntsh.so
5. run the following from the command line as root
1easy_install cx_oracle
6. job done.
Here is a good tutoral on how to use the library files once you have things installed