How to install oci8 for PHP 5 on Ubuntu
งมมาหลายวันเลยเรื่องนี้ เขียนเก็บไว้ซะหน่อยหละกัน
- ORACLE 11g
- LAMP
- UBUNTU 11.04
ลง 3ตัวนี้ไว้ก่อนแล้วนะครับต่อไปก็ลงมือตามเลย
1. Install PEAR and PECL
1.1 IMPORTANT! Install libaio1 library. This is what I was having serious issues with originally.
Download Oracle Instant Client. เอาแค่ Basic and SDK. พอนะครับ
2. Extract the archives.
3. Create symbolic links.
4. Add instant client to system ld.
5. Create a source directory under /opt/oracle . This is where we will house the oci8 libraries.
6. Untar and Compile the oci8 libraries
Enter instantclient,/opt/oracle/instantclient when you are prompted.
7. Enable the extension.
8. Put ORACLE_HOME on Apache Environment /etc/apache2/envvars
9. Restart apache2.
10. Test Code
- ORACLE 11g
- LAMP
- UBUNTU 11.04
ลง 3ตัวนี้ไว้ก่อนแล้วนะครับต่อไปก็ลงมือตามเลย
1. Install PEAR and PECL
sudo apt-get install php-pear
1.1 IMPORTANT! Install libaio1 library. This is what I was having serious issues with originally.
apt-get install libaio1
Download Oracle Instant Client. เอาแค่ Basic and SDK. พอนะครับ
2. Extract the archives.
sudo mkdir -p /opt/oracle
cd /opt/oracle
sudo unzip instantclient-basic-linux-x86-64-11.2.0.2.0.zip
sudo unzip instantclient-sdk-linux-x86-64-11.2.0.2.0.zip
sudo mv /opt/oracle/instantclient_11_2 /opt/oracle/instantclient
3. Create symbolic links.
cd /opt/oracle/instantclient
sudo ln -s libclntsh.so.11.1 libclntsh.so
sudo ln -s libocci.so.11.1 libocci.so
4. Add instant client to system ld.
sudo su -
echo /opt/oracle/instantclient > /etc/ld.so.conf.d/oracle-instantclient
5. Create a source directory under /opt/oracle . This is where we will house the oci8 libraries.
mkdir src
cd src
pecl download oci8
6. Untar and Compile the oci8 libraries
tar xvf oci8-1.2.4.tgz
cd oci8-1.2.4
phpize
#Set the ORACLE_HOME environment variable
export ORACLE_HOME=/opt/oracle/instantclient
./configure --with-oci8=share,instantclient,/opt/oracle/instantclient
make
make install
Enter instantclient,/opt/oracle/instantclient when you are prompted.
7. Enable the extension.
echo extension=oci8.so >> /etc/php5/apache2/php.ini
echo extension=oci8.so >> /etc/php5/cli/php.ini
8. Put ORACLE_HOME on Apache Environment /etc/apache2/envvars
export ORACLE_HOME=/opt/oracle/instantclient
9. Restart apache2.
sudo /etc/init.d/apache2 restart
10. Test Code
///////////////////////////////////////////////////
// Kingmot
//
// Connection test to external Oracle Database
// using OCI8
///////////// Configure this /////////////////////
// TNS Instance Name, or leave blank if local/default Oracle DB
$tnsName = '(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ORACLE_HOST)(PORT = 1521)))(CONNECT_DATA=(SID=DBFS)))';
$username = 'username';
$password = 'password';
///////////// End Configure /////////////////////
// Try connecting to the database
$conn = oci_connect($username, $password, $tnsName);
if (!$conn) {
$e = oci_error(); // For oci_connect errors pass no handle
echo 'FAILED : ' . htmlentities($e[
'message']);
} else {
echo 'OK!';
oci_close($conn);
}
Comments
It is very true of step no 1.1 IMPORTANT! Install libaio1 library..what you said.I hadn't installed this lib libaio1 before while using other articles from the internet.I believe omitting this lib was the source of most of my troubles but now you have sorted me out.
I was setting up a webserver on Ubuntu .11.04 and couldn't figure out why I wasn't getting the OCI8 section when I run in my test.php script.
I have read through many articles and was getting lost and was considering pdo_oci which i learn't couln't handle arrays and shouldn't be used...all that didn't help until I found a procedure I could rely on which is in your blog.
Thanks so much once again and the effort you put into this article is highly appreciated..I now go back to code my application that interfaces with oracle in a relaxed and most thankful manner
I apologize. My english is not good