Installation and configuration of PHP Oracle extended OCI8 under Linux system
Implementing a PHP program to access Oracle DB
Date: 2014.09.02
Write Liu Qunying (Qunyingliu)
-
environment description : Apache version, PHP version, Oracle DB version, Linux release version
-
RPM Package Installation Oracle-instantclient client
-
-
system environment and PHP configuration modification : LD.SO.CONF.D directory configuration file with extended field information in php.ini Modify
-
-
test the link code to confirm that the configuration was successful
Environment Description :
RPM Package installs local Oracle client:
Download the following RPM packages from the Oracle Instant Client website:
Http://www.oracle.com/technetwork/cn/topics/linuxx86-64soft-092277.html
oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
Use the following command to install:
RPM-IVH oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
RPM-IVH oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
RPM-IVH oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
Source code Compilation Install oci8 extension Download:
wget http://pecl.php.net/get/oci8-1.4.10.tgz
Decompression: TAR-ZXVF oci8-1.4.10.tgz
Installation:
CD oci8-1.4.10/usr/local/php/bin/phpize cflags= "-i/usr/lib/oracle/11.2.0.4.0/client64/" CXXFLAGS= "-I/usr/lib/ oracle/11.2.0.4.0/client64/"
./configure--with-php-config=/usr/local/php/bin/php-config--with-oci8=instantclient,/usr/lib/oracle/11.2.0.4.0 /client64/lib/
Make
Make instal
The path to the lphp path and Oracle client are subject to change based on the actual situation.
If a pecl program exists in the system, you can install the oci8 extension by using the following command:
PECL Install Oci8
System environment and PHP configuration modification Modify the system configuration:
echo "/usr/lib/oracle/11.2.0.4.0/client64//lib/"
>/etc/ld.so.conf.d/oracle_client.conf/sbin/ldconfig
To modify the php.ini configuration file:
Extension_dir = "/usr/local/php5/lib/ext"
Extension = "oci8.so"
Oci8.privileged_connect = On
Restart Apache to make the changes effective
/usr/local/apache2/bin/apachectl restart
Test the link code to confirm that the configuration was successful
<?php
$conn = Oci_connect (' Qunyingliu ', ' Testqunyingliu ', ' ORACLE.TEST.LOCALHOST/ORCL ');
Needs to be modified based on actual configuration information
$stid = Oci_parse ($conn, ' Select table_name from User_tables ');
Database operation statements can be modified according to actual requirements
Oci_execute ($stid);
echo "<table>\n";
while ($row = Oci_fetch_array ($stid, oci_assoc+oci_return_nulls)) = = False) {
echo "
\ n ";
foreach ($row as $item) {
echo "<td>". ($item!== null? htmlentities ($item, ent_quotes): ""). " \ n ";
}
echo "\ n";
}
echo "</table>\n";
?>
Related references:
http://php.net/manual/zh/function.oci-connect.php
http://php.net/manual/zh/book.oci8.php
Http://pecl.php.net/get/oci8-1.4.10.tgz
Http://pecl.php.net/package-changelog.php?package=oci8
Http://www.oracle.com/technetwork/cn/topics/linuxx86-64soft-092277.html
This article from "Ops said: from rookie to veteran" blog, please be sure to keep this source http://liuqunying.blog.51cto.com/3984207/1548023
Installation and configuration of PHP Oracle extended OCI8 under Linux system