Linux下安装oracle客户端并配置php5.3_PHP
因项目需要在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;
}
?>

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

MongoDB is suitable for unstructured data and high scalability requirements, while Oracle is suitable for scenarios that require strict data consistency. 1.MongoDB flexibly stores data in different structures, suitable for social media and the Internet of Things. 2. Oracle structured data model ensures data integrity and is suitable for financial transactions. 3.MongoDB scales horizontally through shards, and Oracle scales vertically through RAC. 4.MongoDB has low maintenance costs, while Oracle has high maintenance costs but is fully supported.
