Table of Contents
Linux下安装oracle客户端并配置php5.3,oraclephp5.3
怎在linux下安装Oracle 客户端
Home php教程 php手册 Linux下安装oracle客户端并配置php5.3,oraclephp5.3

Linux下安装oracle客户端并配置php5.3,oraclephp5.3

Jun 13, 2016 am 09:24 AM
linux oracle Install client Configuration

Linux下安装oracle客户端并配置php5.3,oraclephp5.3

因项目需要在linux下进行php5.3的oracle客户端编译,简要介绍一下步骤及走过的弯路。

1.下载Oracle客户端程序包,其中包含OCI、OCCI和JDBC-OCI等相关文件。

1.1下载文件地址

http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
根据操作系统的版本选择对应的软件,我需要的是X86_64选择
Instant Client for Linux x86-64

1.2需要下载的文件如下:

复制代码 代码如下:


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

需要强调的一点是这里需要注册一个oracle的账户才能正常下载。

2.安装Oracle客户端程序包。

将程序包上传到服务器指定目录里

复制代码 代码如下:


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.安装OCI8的php扩展(这里指定php的安装路径为/usr/local/webserver/php)

复制代码 代码如下:


yum install libaio
#yum安装libaio库,libaio是Linux下的一个异步非阻塞接口,它提供了以异步非阻塞方式来读写文件的方式,读写效率比较高
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 外挂模块的编译环境,会根据指定的环境变量生成编译时需要的makefile,phpize是属于php-devel的内容,所以centos下只要运行yum install php-devel进行安装即可
./configure –with-php-config=/usr/local/webserver/php/bin/php-config –with-oci8=/usr/lib/oracle/11.1/client64
make
make install
#编译,安装

需要强调的是make的时候会报错,显示各种找不到库文件,需要对makefile文件进行修改加入oralce的运行库地址
打开makefile,寻找INCLUDE,形式如下:
INCLUDES = -I/usr/local/php/include/php -I/usr/include/oracle/10.2.0.3/client
然后在末尾加上="-I/usr/lib/oracle/11.1/client64,然后重新make就会成功了。

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

在extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"后增加一行:

复制代码 代码如下:


extension = "oci8.so"

5.重启apache让OCI生效

6.在web目录下创建phpinfo.php文件在其中输入一下内容,并通过web访问

复制代码 代码如下:


phpinfo();
?>

如果找到OCI8的部分就说明OCI安装正常了,如下图所示

接下来就能通过php访问oracle数据库了,需要注意的是php下Oracle的连接字符串

复制代码 代码如下:


$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)))(CONNECT_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 "连接oracle成功!";
    return $conn;
}
?>

怎在linux下安装Oracle 客户端

以root用户安装rpm -ivh oracle-instantclient-basic-11.1.0.1-1.x86_64.rpmrpm -ivh oracle-instantclient-sqlplus-11.1.0.1-1.x86_64.rpm配置vim /etc/profile 添加export ORACLE_HOME=/usr/lib/oracle/11.1.0.1/client64export ORACLE_BASE=/usr/lib/oracle/11.1.0.1export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATHexport NLS_LANG=AMERICAN_AMERICA.AL32UTF8设置好环境变量需要重启机器!创建配置文件在ORACLE_HOME目录下创建以下目录network/admin,并创建文件tnsnames.ora,内容如下:vim /usr/lib/oracle/11.1.0.1/client64/network/admin/tnsnames.ora# tnsnames.ora Network Configuration File: /opt/oracle10g/u01/network/admin/tnsnames.ora# Generated by Oracle configuration tools.111 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.15.111)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = dmsdb) ) )测试到ORACLE_HOME/bin目录下,执行命令:[yleesun@centos bin]$ ./sqlplus zxd/zxd@111Copyright (c) 1982, 2011, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL>测试成功!注:如果出现以下错误:sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory说明环境变量没有生效!
 

怎在linux下安装Oracle 客户端

以root用户安装
rpm -ivh oracle-instantclient-basic-11.1.0.1-1.x86_64.rpm
rpm -ivh oracle-instantclient-sqlplus-11.1.0.1-1.x86_64.rpm配置
vim /etc/profile 添加
export ORACLE_HOME=/usr/lib/oracle/11.1.0.1/client64
export ORACLE_BASE=/usr/lib/oracle/11.1.0.1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
设置好环境变量需要重启机器!
创建配置文件
在ORACLE_HOME目录下创建以下目录network/admin,并创建文件tnsnames.ora,内容如下:
vim /usr/lib/oracle/11.1.0.1/client64/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/oracle10g/u01/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.111 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.15.111)(PORT = 1521)))
(CONNECT_DATA =
(SERVICE_NAME = dmsdb)))测试
到ORACLE_HOME/bin目录下,执行命令:
[yleesun@centos bin]$ ./sqlplus zxd/zxd@111
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL测试成功!注:
如果出现以下错误:
说明环境变量没有生效!
 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is Linux actually good for? What is Linux actually good for? Apr 12, 2025 am 12:20 AM

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to open a database in oracle How to open a database in oracle Apr 11, 2025 pm 10:51 PM

The steps to open an Oracle database are as follows: Open the Oracle database client and connect to the database server: connect username/password@servername Use the SQLPLUS command to open the database: SQLPLUS

How to return after oracle submitted How to return after oracle submitted Apr 11, 2025 pm 11:51 PM

Oracle provides the following ways to fall back on committed database changes: Use the ROLLBACK statement to immediately revoke all uncommitted changes. Operation through the database management tool interface. Use Oracle Flashback technology to return to a specific point in time and restore data, flashback logging is required.

How to change the oracle table name How to change the oracle table name Apr 11, 2025 pm 11:54 PM

Two ways to rename Oracle table names: use SQL statements: ALTER TABLE <Old table name> RENAME TO <New table name>;Use PL/SQL statements: EXECUTE IMMEDIATE 'ALTER TABLE ' || :old_table_name || ' RENAME TO ' || :new_table_name;

How to use triggers for oracle How to use triggers for oracle Apr 11, 2025 pm 11:57 PM

Triggers in Oracle are stored procedures used to automatically perform operations after a specific event (insert, update, or delete). They are used in a variety of scenarios, including data verification, auditing, and data maintenance. When creating a trigger, you need to specify the trigger name, association table, trigger event, and trigger time. There are two types of triggers: the BEFORE trigger is fired before the operation, and the AFTER trigger is fired after the operation. For example, the BEFORE INSERT trigger ensures that the age column of the inserted row is not negative.

Using Docker with Linux: A Comprehensive Guide Using Docker with Linux: A Comprehensive Guide Apr 12, 2025 am 12:07 AM

Using Docker on Linux can improve development and deployment efficiency. 1. Install Docker: Use scripts to install Docker on Ubuntu. 2. Verify the installation: Run sudodockerrunhello-world. 3. Basic usage: Create an Nginx container dockerrun-namemy-nginx-p8080:80-dnginx. 4. Advanced usage: Create a custom image, build and run using Dockerfile. 5. Optimization and Best Practices: Follow best practices for writing Dockerfiles using multi-stage builds and DockerCompose.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

See all articles