Di posting sebelumnya saya membagikan cara setting oci 8 di mac os, kali ini saya kan membagikan cara setting oci8 di linux, di sini saya menggunakan Ubutu versi 16.04, permasalahan utama yaitu Ubuntu 16.04 tidak mendukung PHP di bawah versi 7, sehingga saya menggunakan php versi 5.
Berikut tutorial instalasi Apache + MySQL + PHP 5.6 + Oracle Client Oci8 di Ubuntu 16.04 (Xenial Xerus) 64bit.
Catatan : Perintah di bawah ini diakses menggunakan login user root atau awali setiap perintah dengan sudo.
1. Instalasi Apache dan MySQL
Instalasi Apache dan MySQL seperti biasa jalankan terlebih dahulu apt-get install apache2 baru instal apt-get install mysql-server libapache2-mod-auth-mysql
# apt-get install apache2 # apt-get install mysql-server libapache2-mod-auth-mysql
Ikuti setiap langkah – langkahnya. Saya tidak membahas lebih detil karena bisa dilihat di sini.
2. Instalasi PHP 5.6
Karena repo Ubuntu 16.04 secara default hanya mensupport PHP7, maka terlebih dahulu kita hapus instalasi PHP7
# apt-get install aptitude # aptitude purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
kemudian kita tambahkan repo PHP 5.6 yang berada di ppa
# add-apt-repository ppa:ondrej/php
setelah itu kita dapat memasang PHP 5.6
# apt-get update # apt-get install php5.6
setelah selesai kita bisa mengecek versi PHP dengan cara
# php -v PHP 5.6.21-7+donate.sury.org~xenial+1 (cli) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
3. Instalasi Oracle Client dan module OCI8 untuk PHP
a. Oracle Client
Download Oracle Client Basic dan SDK (jika perlu SQL*Plus) dari halaman download resminya yang berekstensi .rpm
Version 12.1.0.2.0
Instant Client Package – Basic
Download oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm (62,587,782 bytes)
Instant Client Package – SQL*Plus
Download oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm (852,271 bytes)
Instant Client Package – SDK
Download oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm (634,803 bytes)
Setelah terdownload, masuk ke direktori hasil download.
Kalau beda server copykan instalannya ke server menggunakan winscp atau filezilla, kebetulan disini saya copykan ka path home.
Login ke server menggunakan ssh contoh : ssh root@192.168.100.21
Setelah masuk, masuk ke directory /home
# cd /home root@vmachine:/home#
Instal packages yang berekstensi .rpm tadi dengan menggunakan bantuan package alien
Jika belum ada alien terlebih dahulu install dahulu
# apt-get install alien
Kemudian jalankan perintah di bawah ini satu persatu :
# alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
# alien -i oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
# alien -i oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
Setelah itu export variabel environment oracle untuk mempermudah akses
# export ORACLE_HOME=/usr/lib/oracle/12.1/client64 # export LD_LIBRARY_PATH=$ORACLE_HOME/lib # export PATH=$PATH:$ORACLE_HOME/bin
Kemudian jalankan script berikut jika sudah export variable :
# nano /etc/ld.so.conf.d/oracle.conf && chmod o+r /etc/ld.so.conf.d/oracle.conf
dan tambahkan baris berikut :
export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
Akhiri dengan menyimpan (Ctrl+X) kemudian Y
# nano /etc/profile.d/oracle.sh && chmod o+r /etc/profile.d/oracle.sh
dan tambahkan baris berikut :
export ORACLE_HOME=/usr/lib/oracle/12.1/client64
Akhiri dengan menyimpan (Ctrl+X) kemudian Y
Setelah itu jalankan ldconfig
# ldconfig
Jika terjadi error /sbin/ldconfig:/usr/lib/oracle/12.1/client64/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} is not a known library type maka silahkan ubah teks oracle.conf di atas menjadi
# /usr/lib/oracle/12.1/client64/lib/
dengan cara membuka kembali
# nano /etc/ld.so.conf.d/oracle.conf && chmod o+r /etc/ld.so.conf.d/oracle.conf
isinya di rubah manjadi
# /usr/lib/oracle/12.1/client64/lib/
b. OCI8 PHP 5.6
Pertama kali kita perlu menginstal PECL dan dependencies nya
# apt-get install php-pear php5-dev libaio1 build-essential php5.6-xml php5.6-dev
Setelah itu kita menjalankan script PECL untuk menginstal OCI 8
# pecl install -Z oci8-2.0.11
Saat instalasi akan ditanyakan Oracle Home Directory, isi dengan lokasi instalasi oracle client
'instantclient,/usr/lib/oracle/12.1/client64/lib'
kita menggunakan oci8 versi 2.0.11 karena versi tersebut mendukung PHP 5.2 – 5.6 menurut situs resminya.
Setelah selesai instalasi OCI8 kita perlu mendaftarkan extension OCI8 ini ke PHP
4. Cek instalasi
Restart server Apache
# service apache2 restart
Buat sebuah file php di direktori webserver
$ cd /var/www/html $ nano tesoci.php
isi dengan script untuk mengetes koneksi ke server oracle, misal
<?php
$OracleListener = "";//disesuaikan dengan server
$OracleUsername = "";//disesuaikan dengan user oracle
$OraclePassword = "";//disesuaikan dengan password oracle
$conn = oci_connect($OracleUsername, $OraclePassword, $OracleListener);
if (!$conn) {
$e = oci_error();
echo $e;
}
$sql = "SELECT * FROM MY_TABLE_NAME";
$stmt = oci_parse($conn, $sql);
oci_execute($stmt);
$row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS);
foreach ($row as $item) {
echo $item;
}
?>
Happy Coding 🙂
I truly prize your work, Great post.
thank you, hope my blog is useful
thanks as easy as blog posts I help you study
I discovered your blog site on google and verify just a few of your early posts. Proceed to maintain up the excellent operate. I simply additional up your RSS feed to my MSN Information Reader. Searching for forward to reading more from you afterward!…
Thank you for visiting the blog
Really nice pattern and fantastic subject material, hardly anything else we want : D.
Thank you for visiting the blog
yxqjkld,Definitely believe that which you said. Your favourite justification appeared to be on the net the simplest thing to remember of.
Thank you for visiting, hopefully it will be useful
avmrzrkc,A very good informative article. I’ve bookmarked your website and will be checking back in future!
Thank you for visiting, hopefully it will be useful
lmpknqb,Quality blog, keep up the good work. You may check our website also!
Thank you for visiting, hopefully it will be useful
abecjassb Yeezy Boost 350,Very informative useful, infect very precise and to the point. I’m a student a Business Education and surfing things on Google and found your website and found it very informative.
Thank you for visiting, hopefully it will be useful
tfcmkpovwkw,Thanks for this useful information, Really amazing. Thanks again. I LOve your BloG
Thank you for visiting, hopefully it will be useful
qaupfpi,A very good informative article. I’ve bookmarked your website and will be checking back in future!
Thank you for visiting, hopefully it will be useful
orabha,Hi there, just wanted to say, I liked this article. It was helpful. Keep on posting!
Thank you for visiting, hopefully it will be useful
yjqipk,Very helpful and best artical information Thanks For sharing.
Thank you for visiting, hopefully it will be useful
vnmwsfgqcoAdidas Yeezy,Definitely believe that which you said. Your favourite justification appeared to be on the net the simplest thing to remember of.
Thank you for visiting, hopefully it will be useful
isolzm,Definitely believe that which you said. Your favourite justification appeared to be on the net the simplest thing to remember of.
Thank you for visiting, hopefully it will be useful
ggjitgvto Yeezy 350,Very helpful and best artical information Thanks For sharing.
Thank you for visiting, hopefully it will be useful
iiounobl,Very informative useful, infect very precise and to the point. I’m a student a Business Education and surfing things on Google and found your website and found it very informative.
thank you, don’t forget to visit my blog again
zaqjysgia,A fascinating discussion is definitely worth comment. I do think that you ought to publish more on this topic, it may not be a taboo wnttghya,subject but generally folks don’t talk about such subjects. To the next! All the best!!
thank you, don’t forget to visit my blog again
xmxfqkjb New Yeezy,If you want a hassle free movies downloading then you must need an app like showbox which may provide best ever user friendly interface.
thank you, don’t forget to visit my blog again
Thank you a lot for giving everyone an extremely special chance to read articles and blog posts from this site. It is often very excellent and full of a good time for me and my office fellow workers to visit the blog at least three times in 7 days to learn the newest tips you have. And indeed, I am also certainly satisfied with the exceptional advice you give. Certain 4 ideas in this article are surely the most impressive I have ever had.
thank you, for visiting the blog, don’t forget to visit again.