Linux下安装oracle客户端并配置php5.3,oraclephp5.3
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;
}
?>
以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说明环境变量没有生效!
以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测试成功!注:
如果出现以下错误:
说明环境变量没有生效!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.