PHP Oracle (php diinstall terpisah dengan server database oracle)

31 Jul

1. download dan install oracle instantclient 11.2 atau yang lebih baru
[root@linux34 php]# rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
Preparing…                ########################################### [100%]
1:oracle-instantclient11.########################################### [100%]
[root@linux34 php]# rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
Preparing…                ########################################### [100%]
1:oracle-instantclient11.########################################### [100%]

2. lakukan konfigurasi oracle
[root@linux34 oci8-1.4.7]# echo /usr/lib/oracle/11.2/client64/lib/ > /etc/ld.so.conf.d/oracle_client.conf

3. download oci8 , yang terbaru dan install
[root@linux34 php]# tar -xvzf oci8-1.4.7.tgz
[root@linux34 php]# cd oci8-1.4.7
[root@linux34 oci8-1.4.7]# phpize
[root@linux34 oci8-1.4.7]# ./configure -with-oci8=instantclient,/usr/lib/oracle/11.2/client64/lib/
[root@linux34 oci8-1.4.7]# make
[root@linux34 oci8-1.4.7]# make install

4. edit /etc/php.ini, tambahkan add extension=oci8.so, kemudian lakukan restart server
# vi /etc/php.ini
# service httpd restart

5. edit /etc/sysconfig/httpd, tambahkan, kemudian lakukan restart server
[root@linux34 var]# mkdir /usr/lib/oracle/11.2/client/network/admin -p
[root@linux34 var]# vi /etc/sysconfig/httpd
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib/
export ORACLE_HOME=/usr/lib/oracle/11.2/client64
export TNS_ADMIN=/usr/lib/oracle/11.2/client64/network/admin

6. tnsnames.ora sudah terkonfigurasi
[root@linux34 var]# cd /usr/lib/oracle/11.2/client64/network/admin
[oracle@test42 admin]$ cat tnsnames.ora
TEST42 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.20.33.42)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = test42)
)
)

7. membuat php : phpinfo.php
# mkdir -p /var/www/html/php
# cd /var/www/html/php
# vi phpinfo.php
<?php
phpinfo();
?>

6. test di browser — http://172.20.33.42/php/phpinfo.php

7. membuat php : oracle01.php dan test dengan browser
<?php
echo “ORACLE_HOME=”.getenv(“ORACLE_HOME”);
echo “<br />\n”;

$ora_conn = oci_connect(“SCOTT”,”TIGER”,”TEST42″);
if (!$ora_conn)
{
$ora_conn_erno = oci_error();
echo ($ora_conn_erno[‘message’].”\n”);
oci_close($ora_conn);
}
else
{
echo “Connection Succesful\n”;
oci_close($ora_conn);
}
?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: