PHP Install Oracle Extensions

Source: Internet
Author: User
Tags install php php online

This article describes the installation method of PHP5.3 connecting Oracle client and PDO_OCI module. Share to everyone for your reference, as follows:

PHP connection to Oracle database is not the best partner, but there is a real need for in-group development. If it's not the right documentation, the process is pretty grueling, and here's a record that the prototype is a foreign blog installing pdo_oci and OCI8 PHP extensions on CentOS 6.4 64bit.

Assuming you have installed PHP environment, PHP version 5.3, to connect to the Oracle server is 11g R2, operating system version CentOS 6.4 x86_64. If you do not have PHP installed, you can install it by using the following command:

?
123 # yum install php php-pdo# yum install php-devel php-pear php-fpm php-gd php-ldap \php-mbstring php-xml php-xmlrpc php- zlib zlib-devel bclibaio glibc

If the Web server uses Apache.

1. Installing Instantclient

Instantclient is a simple client of Oracle's connected database and can connect to an Oracle database with Windows and Linux versions without installing a 500Moracle client. Select the desired version from here for download, just basic and devel two RPM packages.

Installation

?
12 # 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

Soft links

?
12 # ln -s /usr/include/oracle/11.2/client64 /usr/include/oracle/11.2/client# ln -s /usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client

A 64-bit system needs to create a 32-bit soft link, which may be a legacy bug, or the subsequent compilation will be problematic.

The next step is to allow the system to locate the Oracle client's library files and modify the Ld_library_path:

?
123 # vi /etc/profile.d/oracle.shexportORACLE_HOME=/usr/lib/oracle/11.2/client64exportLD_LIBRARY_PATH=$ORACLE_HOME/lib

Execute source/etc/profile.d/oracle.sh to make the environment variable effective.

2. Installing PDO_OCI

In the case of Internet connection, the extension to install PHP online via pecl is very simple, see how to install the Oracle Instantclient and PDO_OCI on the Ubuntu machine.

Download the pdo_oci-1.0.tgz source file from Https://pecl.php.net/package/PDO_OCI.

?
123 # wget https://pecl.php.net/get/PDO_OCI-1.0.tgz# tar -xvf PDO_OCI-1.0.tgz# cd PDO_OCI-1.0

Since Pdo_oci has not been updated for a long time, the following need to edit the Config.m4 file in the odi_oci-1.0 folder to allow it to support 11g:

?
1234567 # 在第10行左右找到与下面类似的代码,添加这两行:eliftest-f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then PDO_OCI_VERSION=11.2# 在第101行左右添加这几行:11.2) PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD) ;;

Compile and install Pdo_oci extensions: (This module can be found in/usr/lib64/php/modules/pdo_oci.so after installation is complete)

?
1234 $ phpize$ ./configure--with-pdo-oci=instantclient,/usr,11.2$ make$ sudo makeinstall

To enable this extension, create a new Pdo_oci.ini file under/etc/php.d/, with the following contents:

?
1 extension=pdo_oci.so

Verify that the installation was successful:

# Php-i|grep OCI

The installation succeeds if you see something like the following:

/etc/php.d/pdo_oci.ini,

?
1 PDO drivers => oci, sqlite

Or

?
1 # php -m

3. Installing OCI8

Download the oci8-2.0.8.tgz source file from Https://pecl.php.net/package/oci8.

?
123 # wget https://pecl.php.net/get/oci8-2.0.8.tgz# tar -xvf oci8-2.0.8.tgz# cd oci8-2.0.8

Compile and install the OCI8 extension:

?
1234 # phpize# ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib# make# make install

To enable this extension, create a new Oci8.ini file under/etc/php.d/, with the following contents:

?
1 extension=oci8.so

Verify that the installation was successful:

?
1234567891011121314 # php -i|grep oci8/etc/php.d/oci8.ini,oci8oci8.connection_class => no value => no valueoci8.default_prefetch => 100 => 100oci8.events => Off => Offoci8.max_persistent => -1 => -1oci8.old_oci_close_semantics => Off => Offoci8.persistent_timeout => -1 => -1oci8.ping_interval => 60 => 60oci8.privileged_connect => Off => Offoci8.statement_cache_size => 20 => 20OLDPWD => /usr/local/src/oci8-2.0.8_SERVER["OLDPWD"] => /usr/local/src/oci8-2.0.8

Finally, don't forget to restart the reverse Web server, such as Apache, by Phpinfo () to ensure that the extension is installed successfully.

4. Test the connection

Create testoci.php in your Web server like Apache's PHP directory:

?
1234567891011121314 <?php$conn = oci_connect(‘username‘, ‘password‘, ‘172.29.88.178/DBTEST‘);$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";?>

Visit this page and you should be able to get the results.

PHP Install Oracle Extensions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.