
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:
- oracle-instantclient basic
- oracle-instantclient devel
Download Instant client di sini
1. 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.
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) : " ")."</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 🙂
I as well believe thence, perfectly composed post! .
thank u
I was able to find good advice from your articles.
thank u
Appreciation to my father who shared with me
on the topic of this website, this weblog is
actually awesome.
Thank you for the advice and input, I will improve the quality of my blog
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.
I write according to the case that I have experienced
thanks as easy as blog posts I help you study
Good site you have here.. It’s hard to find good quality writing like yours nowadays.
I truly appreciate individuals like you! Take care!!
Thank you for visiting the blog
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!
Thank you for visiting the blog
This piece of writing is truly a pleasant one it helps new the web visitors, who are wishing in favor of blogging.
I support blogs because I like to write even though I’m still learning to write a blog
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.
Thank you for visiting the blog
Wow, wonderful blog layout! How long have you been blogging for?
you made blogging look easy. The overall look of your website is fantastic, as well as the content!
Thank you for visiting the blog
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.
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.
Thank you for visiting the blog
Fastidious answer back in return of this question with real arguments and explaining everything
about that.
thanks for the advice
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!
Thank you for visiting the blog
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
Thank you for visiting the blog
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.
Thank you for visiting the blog
Its not my first time to pay a quick visit this web page, i am browsing this website dailly and obtain nice information from here every day.
Thank you for visiting the blog
No matter if some one searches for his vital thing, so he/she desires to be
available that in detail, so that thing is maintained over here.
Thank you for visiting the blog
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.
Thank you for visiting the blog
Thanks very interesting blog!
Thank you for visiting the blog
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
Thank you for visiting the blog
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.
Thank you for visiting the blog
thank you, don’t forget to visit my blog again
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!
Thank you for visiting the blog
It’s very effortless to fіnd out any matter on net as compared to books, as I found this pieсe
of writing at this website.
Thank you for visiting the blog
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.
Thank you for visiting the blog
ktk bullies is family owned and we provide alot of help in the dog community so check
us out and thank you in advance
Thank you for visiting the blog
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!
thank you, hope my blog is useful
Thank you for visiting the blog
That is a good tip especially to those new to the blogosphere.
Short but very precise info… Many thanks for sharing
this one. A must read article!
Thank you for visiting, hopefully it will be useful
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
Thank you for visiting, hopefully it will be useful
Hey there! I simply wish to give you a big thumbs up for your
great info you have got right here on this post. I will
be returning to your site for more soon.
Thank you for visiting, hopefully it will be useful
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.
Thank you for visiting, hopefully it will be useful
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!!
Thank you for visiting, hopefully it will be useful
Pretty! This was a really wonderful article. Thanks for providing these details.
Thank you for visiting, hopefully it will be useful
It is really a nice and helpful piece of information.
I’m happy that you simply shared this useful info with us.
Please stay us informed like this. Thanks for sharing.
Thank you for visiting, hopefully it will be useful
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.
thank you, don’t forget to visit my blog again
I know this site presents quality depending posts
and extra information, is there any other site which offers these kinds of information in quality?
Thank you for visiting, hopefully it will be useful
What’s up colleagues, its fantastic post regarding tutoringand completely defined, keep it up all the
time.
Thank you for visiting, hopefully it will be useful
Hi there it’s me, I am also visiting this website on a regular basis, this web site is
actually pleasant and the people are actually sharing good thoughts.
Thank you for visiting, hopefully it will be useful
It’s awesome designed for me to have a web site, which is good designed for my experience.
thanks admin
Thank you for visiting, hopefully it will be useful
Hi! Do you use Twitter? I’d like to follow you if that would be ok.
I’m undoubtedly enjoying your blog and look forward to new updates.
Thank you for visiting, hopefully it will be useful
When some one searches for his required thing, thus he/she wishes
to be available that in detail, so that thing is maintained over here.
Thank you for visiting, hopefully it will be useful
Hello, just wanted to tell you, I enjoyed this blog post.
It was practical. Keep on posting!
Thank you for visiting, hopefully it will be useful
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!
thank you for the advice and input I will immediately fix it
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!
to delete other people’s comments, the solution comments that you previously made must be deleted
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.
Thank you for visiting the blog, hopefully it’s useful
bookmarked!!, I like your blog!
thank you, for visiting the blog, don’t forget to visit again.