Configure PHP connection to Oracle DB

Configure PHP connection to Oracle DB – the RPM way

Lets begin

A. Use PHP RPMs packages
1. Install Apache if not installed
CODE:
# yum install httpd


2. Download Oracle Client Software -- if you are using GUI
or download Oracle InstantClient BasicLite (the rpm version) -- I choose this and install it.
to get latest version download it from http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html
CODE:
# rpm –ivh oracle-instantclient-basiclite-*.rpm

my copy of Oracle Instant Client BasicLite is here
http://www.am3n.profusehost.net/phpoci/oracle-instantclient-basic-10.2.0.3-1.i386.rpm

3. Install PHP and makesure you installed php-oci8 module, other modules you can install it if you like
CODE:
# rpm -ivh php-5*.rpm php-oci8-*.rpm php-pear-*.rpm

I am not using CentOS version because it's not provide oci8 module. But I am using PHP from Miracle Linux - Asianux which also look-like Redhat derivatives distro. They provide complete PHP module including oci8.
Download it from my mirror here.
http://www.am3n.profusehost.net/phprh4/

Info about Miracle Linux - Asianux
http://en.wikipedia.org/wiki/Miracle_Linux
Complete PHP modules from Miracle Linux
http://www.miraclelinux.com/update/linux/list.php?errata_id=249

4. Create local variable to connect to Oracle, for NLS_LANG you can set with your locale.
CODE:

# vi /etc/profiles
LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client/lib
export LD_LIBRARY_PATH
NLS_LANG=AMERICAN_AMERICA.UTF8
export NLS_LANG


5. Update linux Library thingy... (locate the oracle library if you use differrent version)
CODE:
# echo /usr/lib/oracle/10.2.0.3/client/bin/ >> /etc/ld.so.conf
# echo /usr/lib/oracle/10.2.0.3/client/lib/ >> /etc/ld.so.conf
# ldconfig
# cd /usr/lib/oracle/10.2.0.3/client/lib/
# ln -s libclntsh.so.10.1 libclntsh.so
# ln -s libocci.so.10.1 libocci.so


6. (Re-)Start the Apache
CODE:
# service httpd restart



B. Use your current PHP version from CentOS
If you already install your PHP and don't want to replace it with older version and/or your current version of PHP didn't provide php-oci8 packages you can install it using the following steps
This how to is modification of PHP-OCI8 in Ubuntu Forum
http://www.ubuntuforums.org/archive/index.php/t-92528.html

1. Install Oracle InstantClient
download it from http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html
CODE:
# rpm -ivh oracle-instantclient-basic-10.2.0.3-1.i386.rpm
# rpm -ivh oracle-instantclient-devel-10.2.0.3-1.i386.rpm

My copy is here
http://www.am3n.profusehost.net/phpoci/oracle-instantclient-basiclite-10.2.0.3-1.i386.rpm
http://www.am3n.profusehost.net/phpoci/oracle-instantclient-devel-10.2.0.3-1.i386.rpm

2. Configure linux library thingie...
CODE:
# echo /usr/lib/oracle/10.2.0.3/client/bin/ >> /etc/ld.so.conf
# echo /usr/lib/oracle/10.2.0.3/client/lib/ >> /etc/ld.so.conf

# ldconfig

3. Install oci8 via pear
Make sure you already install php-devel package (and have upgrade to latest version)

CODE:
# cd /usr/local/src
# pear download oci8
# tar xzf oci8-1.2.3.tgz
# cd oci8-1.2.3
# phpize
# ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/10.2.0.3/client/lib/
# make
# make install

My copy of oci8 is here
http://www.am3n.profusehost.net/phpoci/oci8-1.2.3.tgz

4. Enable oci8
CODE:
# vi /etc/php.d/oci8.ini
; Enable oci8 extention module
extension=oci8.so


5. (Re-)Start the Apache
CODE:
# service httpd restart




Just want to make sure if your php is already configure with oci8 module create a php file with phpinfo() function
Create phpinfo file
CODE:
# vi /var/www/html/phpinfo.php
< ?php phpinfo() ?>


View phpinfo. http://yourserver/phpinfo.php
You should see something like this
CODE:

oci8
OCI8 Support enabled
Revision $Revision: 1.257.2.8 $
Active Persistent Links 0
Active Links 0
Oracle Version 10.1
Compile-time
ORACLE_HOME /opt/oracle/product/10.1.0
Libraries Used -Wl,-rpath,/opt/oracle/product/10.1.0/lib -
L/opt/oracle/product/10.1.0/lib -lclntsh
Temporary Lob support enabled
Collections support enabled

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23520424/viewspace-703980/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23520424/viewspace-703980/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值