Howto: Install Oracle Instant Client and PHP OCI8 module
posted on 08 Jun 2010 15:58 by smom2002
Download the new Instantclient and SDK zip files from Oracle.
http://www.oracle.com/technology/tech/oci/instantclient/index.html
In my case the files are called Basic.zip and Sdk.zip Initially these files will be saved in my home directory under the Documents folder.
/home/ubuntu/Documents/
create a directory to house the zip files once they are uncompressed
root@ubuntu-desktop:~# mkdir /opt/oracle
move the .zip files in the “Documents” directory to the /opt/oracle directory
root@ubuntu-desktop:~# mv /home/ubuntu/Documents/*.zip /opt/oracle
Change to the /opt/oracle directory
root@ubuntu-desktop:~# cd /opt/oracle
Unzip the files
root@ubuntu-desktop:/opt/oracle# unzip \*.zip
rename instantclient directory
root@ubuntu-desktop:/opt/oracle# mv instantclient_11_1 instantclient
Change directory to instantclient, list the files
root@ubuntu-desktop:/opt/oracle# cd instantclient
Create symbolic links
root@ubuntu-desktop:/opt/oracle# ln –s libclntsh.so.11.1 libclntsh.so
root@ubuntu-desktop:/opt/oracle# ln –s libocci.so.11.1 libocci.so
Create a source directory under /opt/oracle . This is where we will house the oci8 libraries.
root@ubuntu-desktop:/opt/oracle# mkdir /opt/oracle/src
Change the directory to /opt/oracle/src and download the oci8 tar using pecl
root@ubuntu-desktop:/opt/oracle# cd /opt/oracle/src
root@ubuntu-desktop:/opt/oracle/src# pecl download oci8
Untar the oci8 libraries
root@ubuntu-desktop:/opt/oracle/src# tar xvf oci8-1.2.4.tgz
Change to the newly created oci8-1.2.4 directory and issue the following commands
root@ubuntu-desktop:/opt/oracle/src# cd oci8-1.2.4
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# phpize
Set the ORACLE_HOME environment variable
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# export ORACLE_HOME=/opt/oracle/instantclient
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# echo $ORACLE_HOME
/opt/oracle/instantclient
Configure oci8 to install with the necessary parameters
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# ./configure --with-oci8=share,instantclient,/opt/oracle/instantclient
run make to compile
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# make
install oci8
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# make install
insert the extension=oci8.so into the php.ini and cli.ini files
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# echo extension=oci8.so >> /etc/php5/apache2/php.ini
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# echo extension=oci8.so >> /etc/php5/cli/php.ini
restart apache
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# /etc/init.d/apache2 restart
create a phpinfo.php file in /var/www
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# vi /var/www/phpinfo.php
Now go to your browser and run the phpinfo file and look for the oci8 module
http://localhost/phpinfo.php
Create a empty script to test your Oracle Connection
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# vi /home/ubuntu/oratest.php
Copy and Paste this PHP code into your script and change the variables accordingly
<?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
}
?>
Test the connection
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4# php /home/ubuntu/oratest.php
Connection Succesful
root@ubuntu-desktop:/opt/oracle/src/oci8-1.2.4#
(http://ubuntuforums.org/archive/index.php/t-92528.html)
สงสารแกจริงๆนะเต้ แต่ไม่รู้ทำไงเหมือนกัน ถ้าเค้าไม่เอาแกไปเลี่ยง ป่านนี้แกจะเป็นไงบ้างก็ไม่รู้ แต่ที่รู้ตอนนี้แกเป็นแบบนี้ ....
กินข้าวเสร็จ ไปกินไอติมต่อ แล้วก็นั่งคิดว่าเอาไงกันดี 3 ทุ่มกว่าแล้วตกลงว่าเอาวะ ฝังหมากัน กลับมาใน มอ. เราก็จะไปหาจอบแถวๆ คณะทรัพย์ฯ เป็นคณะ ที่เหมาะสุดแล้วที่จะมีจอบ แถวเรื่อนเพาะชำนี่ล่ะ แต่มีรถตู้ขับตามมาแผนการเลยล้ม มาถึงวิศวะ ใต้ภาคคอมฯ หาจอบ ..มันจะมีมั้ยเนี่ย ไม่เจอจอบแต่เจอ น้องกาน น้องจา น้องรุ่ง น้องๆน่ารัก ไม่มีจอบ แต่ก็อยากช่วย กานยังไปชวน น้องโดม กับ น้องเต้ย มาช่วยอีก (ปกติไม่ใช้คำว่าน้องนำหน้าพวกแกเล้ย 5 5 วันนี้ขอซักวัน ให้เกียรติๆๆ ) เราก็เลยบอกให้รอใต้ภาคฯ เดี๋ยวไปหาจอบมาเองเดินมาได้นิดนึง (อ้อ จิก น้องจามาด้วย) เจอกองทราย มีจอบ โห! เหมือนฟ้ามีตานะเนี่ย เราเลยจัดการแบ่งเป็น 2 ทีม ทีมที่ 1 ไปขุดหลุม ทีมที่ 2 ไปเก็บศพน้องหมา ว่าแล้วก็แยกย้ายกันขึ้นเขา (ไหล่เขา) ไม่มีไฟฉาย ไม่มีแสตนอิน เล่นจริงเจ็บจริงทุกคน ^^ กานไปหยิบถุงขยะของภาคฯมาให้ใส่น้องหมา จาไปเก็บหมากับรุ่ง เรา หลอกล่อไฉน(เพราะสนิทกับไฉนที่สุด
) ให้ตุ๊ช่วยหลอกลูกหมาที่เหลือ เสียงอีกทีมนำโดย เต้ย โดม กาน ขุดหลุมเสียงดังฟังชัด เราต้องคุยกับไฉนอยู่นาน จนให้จากับรุ่งเอาร่างน้องหมาในถุงไปฝัง สงสารไฉนมาก ไฉนวิ่งไปดมกลิ่นลูกแล้วพยายามจะวิ่งตามไป เราต้องหลอกให้อยู่จนกว่าอีกทีมจะฝังเสร็จ สุดท้ายภาระกิจเสร็จสิ้นไปด้วยดี แต่สงสารไฉนมาก ลูกทั้งตัว หายไป ตามันเศร้ามาก