Connect oracle database ke php di server Redhat/CentOS/Fedora

oracle-php-oci

Di posting ini, saya akan mencoba menjelaskan bagaimana cara menghubungkan database Oracle dari PHP di server Redhat/ CentOS/Fedora, Secara step by step. Cara yang paling mudah mengkonfigurasi php untuk mengakses database oracle dengan menggunakan Oracle Instant Client. Tahapannya mulai dari cara menginstall PHP dengan OCI8 Extension dan cara menginstall Oracle Instant Client di Server Redhat/CentOS/Fedora. OCI8 sendiri adalah ekstensi PHP untuk menghubungkan ke Oracle Database. Yang perlu di Install yaitu : oracle-instant-client dan php oci8 extension. Saya asumsikan PHP dan pecl sudah terinstall di server.

Tahap Pertama :

Periksa arsitektur server dan versi OS Anda :

# uname -a
Linux localhost 2.6.32-220.el6.x86_64 #1 SMP Wed Nov 9 08:03:13 EST
2011 x86_64 x86_64 x86_64 GNU/Linux

el6 berarti itu adalah perusahaan linux 6 dan x86_64 berarti itu adalah mesin 64 bit. Untuk mesin 32 bit itu adalah i386.

Tahap kedua  :Download dua RPM paket:

  1. oracle-instantclient basic
  2. oracle-instantclient devel

 Download Instant client di sini

1. Instant Client Linux x86-64(64-bit)

Instant Client Linux x86-64(64-bit)

2. Instant Client Devel Linux x86-64(64-bit) dengan Gulir ke bawah dan download paket instant instant  devel rpm.

Instant Client Devel Linux x86-64(64-bit)

Tahap Ketiga : Instal RPM di root user

# rpm -Uvh oracle-instantclient12.1-basic-12.2.0.1.0-1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:oracle-instantclient12.########################################### [100%]
# rpm -Uvh oracle-instantclient12.1-devel-12.2.0.1.0-1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:oracle-instantclient12.########################################### [100%]

Instant client atau file hasil instalasi di simpan secara default di   /usr/lib/oracle/12.2/client64/ untuk OS 64 bit sedangkan untuk OS 32 bit tersimpan di  /usr/lib/oracle/12.1/client/

Tahap Empat : Set environment variables ORACLE_HOME dan LD_LIBRARY_PATH

# ORACLE_HOME=/usr/lib/oracle/12.2/client64; export ORACLE_HOME
# LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH

Anda juga harus menambahkan dua baris di atas di file ~ / .bash_profile. Edit file dengan vim editor dan tambahkan baris di atas PATH = $ PATH: $ HOME / bin

#vim  ~/.bash_profile

Setelah diedit file akan menjadi :

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

ORACLE_HOME=/usr/lib/oracle/12.2/client64; export ORACLE_HOME
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
PATH=$PATH:$HOME/bin

export PATH

Tahap kelima : Periksa paket php-pear dan php-devel yang diinstal oleh perintah ini. Anda harus menginstal paket ini

# rpm -qa | grep -i php
php-5.3.3-3.el6_1.3.x86_64
php-cli-5.3.3-3.el6_1.3.x86_64
php-devel-5.3.3-3.el6_1.3.x86_64
php-common-5.3.3-3.el6_1.3.x86_64
php-mysql-5.3.3-3.el6_1.3.x86_64
php-soap-5.3.3-3.el6_1.3.x86_64
php-pear-1.9.4-4.el6.noarch
php-gd-5.3.3-3.el6_1.3.x86_64

Tahap ke-Enam : Install ektensi oci8

# pecl install oci8

Setelah itu anda akan ditanya tempat penyampanan direktori dari instant client seperti berikut : kemudian masukan alamatnya instant client :

instantclient,/usr/lib/oracle/12.2/client64/lib

Saat proses dijalankan :

Please provide the path to the ORACLE_HOME directory. 
Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :
instantclient,/usr/lib/oracle/12.2/client64/lib

Setelah menekan enter, pada bagian akhir anda akan melihat baris “Build process completed successfully”

Build process completed successfully
Installing '/usr/lib64/php/modules/oci8.so'
install ok: channel://pecl.php.net/oci8-2.0.6
configuration option "php_ini" is not set to php.ini location
You should add "extension=oci8.so" to php.ini

Tambahkan “extension = oci8.so” ke file php.ini tepat di bawah baris [PHP] dan sepertinya

[PHP]
extension=oci8.so
;;;;;;;;;;;;;;;;;;;
; About php.ini   ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.

Tahap ke-Tujuh : Restart Web Server(Apache or Nginx)

# /etc/init.d/httpd restart

Sekarang cek oci8 telah terinstal , karena oci8 sudah diaktifkan.

# echo "<?php print phpinfo();?>" | php | grep -i oci
oci8
OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.0.6
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100
oci8.events => Off => Off
oci8.max_persistent => -1 => -1
oci8.old_oci_close_semantics => Off => Off
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20

Sekarang Anda telah menginstal oci8 dan Anda dapat menulis kode untuk menghubungkan ke Oracle Database. Berikut adalah contoh Kode PHP

<?php

$conn = oci_connect('test_user', 'test_password', 'mymachine.mydomain/orcl');

$stid = oci_parse($conn, 'select table_name from user_tables');
oci_execute($stid);

echo "<table>\n";
while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "  <td>".($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;")."</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";

?>
test_user is user of the  Database
test_password is the password of the database
mymachine.mydomain is the hostname.domain of the Database. You can put IP directly here.
orcl is the SID of the Database.

Prosedur di atas mengenai “Connect Oracle Database dari PHP ke server Redhat / CentOS  / Fedora “.

Sekian tutorial kali ini. semoga bermanfaat 🙂

Pos terkait

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Situs ini menggunakan Akismet untuk mengurangi spam. Pelajari bagaimana data komentar Anda diproses.

0 Komentar

  1. Linnk eхⅽhangе is nothing else but it is just placing the other person’ѕ web site link on youг page at appropriɑte place and other pеrson will also dо
    similar in support of you.

  2. Howdy! I know this is sort of off-topic but I had to ask.

    Does managing a well-established website such as yours
    require a massive amount work? I am completely new to running a blog however
    I do write in my diary daily. I’d like to start a blog so I can easily share my personal
    experience and thoughts online. Please let me
    know if you have any kind of recommendations or tips for brand
    new aspiring blog owners. Appreciate it!

  3. Simply want to say your article is as astounding. The clearness in your post
    is simply great and i can think you are knowledgeable on this subject.
    Well with your permission allow me to seize your RSS feed to stay up to date with coming near near post.
    Thank you one million and please keep up the enjoyable work.

  4. Its like you read my mind! You seem to know so much about this, like you wrote the book
    in it or something. I think that you could do with some
    pics to drive the message home a little bit, but instead of that, this is
    wonderful blog. A fantastic read. I will definitely be back.

  5. I’m impressed, I must say. Rarely do I encounter a blog that’s both educative and engaging, and let me tell you, you have
    hit the nail on the head. The problem is an issue that too
    few folks are speaking intelligently about. I am very happy that I found this
    in my search for something regarding this.

  6. I truly love your site.. Pleasant colors & theme.
    Did you make this web site yourself? Please reply back as I’m
    looking to create my own website and want to know where you got this from or exactly what the theme
    is called. Many thanks!

  7. Definitely believe that which you said. Your favorite reason appeared to
    be at the web the easiest factor to remember of. I say to you, I
    certainly get annoyed while people consider concerns that they
    just do not understand about. You managed to hit
    the nail upon the top and also outlined out the entire
    thing without having side-effects , other people can take a signal.
    Will likely be back to get more. Thanks

  8. We’re a bunch of volunteers and starting a new scheme in our community.
    Your web site offered us with useful information to work on. You have done a formidable process and our entire community can be grateful to you.

  9. I loved as much as you will receive carried out right here.
    The sketch is tasteful, your authored subject matter stylish.
    nonetheless, you command get got an edginess over that you wish be delivering the following.
    unwell unquestionably come further formerly again since exactly the same nearly very often inside case
    you shield this increase.

  10. Nice blog right here! Also your web site rather a lot up fast!
    What host are you the usage of? Can I am getting your affiliate hyperlink
    in your host? I wish my site loaded up as fast as yours lol

  11. Great post. I was checking constantly this weblog and I’m inspired!
    Extremely helpful info specifically the ultimate part 🙂 I care for such info
    a lot. I was looking for this particular info for a long time.
    Thanks and best of luck.

  12. Thanks for a marvelous posting! I certainly enjoyed reading it, you can be a great author.

    I will be sure to bookmark your blog and will often come back sometime soon. I
    want to encourage you to ultimately continue your great posts,
    have a nice afternoon!

  13. What’s Taking place i am new to this, I stumbled upon this I’ve discovered It positively useful and it has aided me out
    loads. I am hoping to give a contribution &
    help different users like its helped me. Good job.

  14. Pretty nice post. I just stumbled upon your blog and wished to say that
    I’ve really enjoyed browsing your blog posts.
    In any case I will be subscribing to your rss feed and I hope you write again soon!

  15. Wonderful blog! I found it while searching on Yahoo News.

    Do you have any suggestions on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!
    Thank you

  16. Great goods from you, man. I have take note your stuff previous to and you’re just extremely excellent.
    I actually like what you have got here, really like what you’re saying and the best way by which you assert it.
    You are making it enjoyable and you still take care of to stay it smart.

    I can not wait to read much more from you.

    This is actually a wonderful website.

  17. Hi, i think that i noticed you visited my web site thus
    i got here to return the favor?.I am attempting to in finding things to enhance my website!I assume its adequate to use some of your concepts!!

  18. Thank you for some other excellent article. Where else could anyone get
    that kind of information in such a perfect way of writing?

    I’ve a presentation next week, and I am on the search for such info.

  19. Hi, I think your blog might be having browser compatibility issues.
    When I look at your blog in Opera, it looks fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, awesome
    blog!

  20. When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a
    comment is added I get four emails with the same comment.
    Is there any way you can remove people from that service?

    Many thanks!

  21. After looking into a few of the blog posts on your blog, I seriously like your technique of writing a blog.

    I added it to my bookmark site list and will be checking back
    soon. Please check out my web site as well and tell me your
    opinion.