Install Oracle clients under Linux and configure php5.3_php tips

Source: Internet
Author: User
Tags install php phpinfo sqlplus

Because the project needs to be under Linux for php5.3 Oracle client compiler, briefly introduce the steps and the detour.

1. Download the Oracle client package, which contains related files such as OCI, Occi and Jdbc-oci.

1.1 Download file Address

Http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
According to the version of the operating system to choose the corresponding software, I need is x86_64 selection
Instant Client for Linux x86-64

1.2 Files that need to be downloaded are as follows:

Copy Code code as follows:

oracle-instantclient11.1-basic-11.1.0.7.0-1.x86_64.rpm
oracle-instantclient11.1-devel-11.1.0.7.0-1.x86_64.rpm
oracle-instantclient11.1-sqlplus-11.1.0.7.0-1.x86_64.rpm

The point to be stressed here is that you need to register an Oracle account to download normally.

2. Install an Oracle client package.

Upload the package to the server specified directory

Copy Code code as follows:

chmod +x *.rpm
#给RPM包赋执行权限
RPM-IVH oracle-instantclient11.1-basic-11.1.0.7.0-1.x86_64.rpm oracle-instantclient11.1-devel-11.1.0.7.0-1.x86_ 64.rpm oracle-instantclient11.1-sqlplus-11.1.0.7.0-1.x86_64.rpm
#安装RPM包
echo "/usr/lib/oracle/11.1/client64/lib/" >/etc/ld.so.conf.d/oracle_client.conf
#将库路径加到默认加载中
/sbin/ldconfig
#重新加载动态链接库

3. Install OCI8 PHP extensions (this specifies that the PHP installation path is/usr/local/webserver/php)

Copy Code code as follows:

Yum Install Libaio
#yum安装libaio库, Libaio is an asynchronous, non-blocking interface under Linux that provides a way to read and write files in an asynchronous, Non-blocking way, with a higher read/write efficiency
wget http://pecl.php.net/get/oci8-1.4.10.tgz
#下载OCI扩展
Tar zxvf oci8-1.4.10.tgz
#解压
CD oci8-1.4.10
/usr/local/webserver/php/bin/phpize cflags= "-i/usr/lib/oracle/11.1/client64" cxxflags= "-I/usr/lib/oracle/11.1/ Client64 "
#使用phpize准备 PHP Plug-in module of the compiler environment, will be based on the specified environment variables to build the required makefile,phpize is php-devel content, so CentOS under just run yum install Php-devel can be installed
./configure–with-php-config=/usr/local/webserver/php/bin/php-config–with-oci8=/usr/lib/oracle/11.1/client64
Make
Make install
#编译, installing

Need to emphasize is make when the error, show a variety of libraries can not find the file, need to modify the makefile file to add Oralce runtime address
Open makefile and look for include in the following form:
INCLUDES =-i/usr/local/php/include/php-i/usr/include/oracle/10.2.0.3/client
Then add = "-i/usr/lib/oracle/11.1/client64" at the end and then make it again.

4. Modify PHP.ini (/usr/local/webserver/php/etc/php.ini)

Add a row after Extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/":

Copy Code code as follows:

Extension = "oci8.so"

5. Restart Apache for OCI to take effect

6. Create a phpinfo.php file in the Web directory to enter content in it and access through the Web

Copy Code code as follows:

<?php
Phpinfo ();
?>

If the OCI8 is found, the OCI is installed properly, as shown in the following figure

Next you will be able to access the Oracle database via PHP, and you need to be aware of the Oracle connection string under PHP

Copy Code code as follows:

<?php
$username = ' * * *;
$PASSWD = ' * * *;
$protocol = ' TCP ';
$SERVICE _name= ' * * * *;
$ORACLE _server_ip_address= ' ***.***.***.*** ';
$Port = ' 1521′;
$db = "(description= (address_list = (address = (PROTOCOL = $protocol) (HOST = $ORACLE _server_ip_address) (PORT = $Port))) (CO Nnect_data= (sid= $SERVICE _name))) ";
$conn = Oci_connect ($username, $passwd, $db);
PUTENV ("Nls_lang=simplified Chinese_china.") Al32utf8 ");
if (! $conn) {
$e = Oci_error ();
Print htmlentities ($e [' message ']);
Exit
}else {
echo "Connect Oracle successfully! ";
return $conn;
}
?>

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.