整合Oracle 10g、Apache 2.0、Php 5
欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 基本介绍 2004 年 7 月 13 日 , PHP 官方站点正式发布了 PHP 5 。 Oracle 在 2004 年 8 月宣布将在拳头产品 Application Server 中提供对 PHP 的支持。先是在 Oracle Application Server 10g ( 9.0
欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入
基本介绍
在 OTN 上已经有文档描述如何进行
Oracle、Apache、PHP三者之间的关系不妨借用一下这张示意图(原图地址):
本文假定您的 Oracle
http://www.dbanotes.nethttp://oracle.chinaitlab.com/Install-Oracle10g-RHEL3.htm
确定自己的 Oracle 处于可用状态。
本文所拥的操作系统为 Fedora Core 3 Linux,Oracle 版本为10 R1 (
下载所需文件:HTTPD 和 PHP 5
HTTPD - httpd://httpd.apache.org (目前的版本是
PHP 5 - http://www.php.net (最新版本是
安装HTTPD
需要说明的是,现在 Apache 社区不推荐把 Apache 2.0 用在产品环境中.
[root@FC3 software]# tar -zxvf httpd-
[root@FC3 software]# cd httpd-2.0.52
[root@FC3 httpd-2.0.52]# ./configure --prefix=/usr/local/apache \
--enable-module=so
[root@FC3 httpd-2.0.52]# make clean
[root@FC3 httpd-2.0.52]# make
[root@FC3 httpd-2.0.52]# make install
[root@FC3 httpd-2.0.52]# /usr/local/apache/bin/apachectl
[root@FC3 httpd-2.0.52]# /usr/local/apache/bin/apachectl stop
安装说明:第三行指定 Apache 的架构独立的文件安装位置。同时指定将用模块的形式。
如果为了方便的话,可以创建两个脚本控制 Apache 的启动与关闭。
[root@FC3 ~]# vi /bin/
添加如下内容:
#!/bin/sh
ORACLE_HOME=/u01/app/oracle/product/
ORACLE_SID=TEST
export ORACLE_HOME ORACLE_SID
echo
/usr/local/apache/bin/apachectl
创建关闭 apache 的脚本:
[root@FC3 ~]# vi /bin/stopapache
添加如下内容:
#!/bin/sh
ORACLE_HOME=/u01/app/oracle/product/
ORACLE_SID=TEST
export ORACLE_HOME ORACLE_SID
echo
/usr/local/apache/bin/apachectl stop
修改文件权限:
[root@FC3 ~] chmod +x /bin/
安装 PHP 5
[root@FC3 software]# tar -xjf php-
[root@FC3 software]# cd php-5.0.2
[root@FC3 php-5.0.2]# export ORACLE_BASE=/u01/app/oracle
[root@FC3 php-5.0.2]# export ORACLE_HOME=$ORACLE_BASE/product/10.1.0/db_1
[root@FC3 php-5.0.2]# export ORACLE_SID=TEST
[root@FC3 php-5.0.2]# export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
[root@FC3 php-5.0.2]# export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
[root@FC3 php-5.0.2]# ./configure --with-apxs2=/usr/local/apache/bin/apxs \
--with-oci8=$ORACLE_HOME
[root@FC3 php-5.0.2]# make clean
[root@FC3 php-5.0.2]# make
[root@FC3 php-5.0.2]# make install
[root@FC3 php-5.0.2]# cp php.ini-dist /usr/local/lib/php.ini
安装说明:第三到七行其实有些罗嗦了,其目的是控制 root 用户的环境变量,其实也可以直接在 root 用户的.bash_profile文件中制定环境变量。当然了,也可以用 oracle 用户来进行 configure 与 make 。第八行中的 --with-oci8=$ORACLE_HOME 激活 oci8 支持。
接下来需要修改httpd.conf 文件的内容:
[root@FC3 php-
添加如下内容:
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
重新启动 apache:
[root@FC3 ]# /bin/stopapache
[root@FC3 ]# /bin/
测试 PHP 模块
测试 PHP 模块是否已经可用。当然是标准办法,写一个包含如下内容的PHP页面 info.php:
从浏览器中查看该页面输出内容。
注意,该页面中的内容 Configure Command 那一行中的内容是否包括如下内容:
'--with-apxs2=/usr/local/apache/bin/apxs'
'--with-oci8=/u01/app/oracle/product/
注意:在测试之后,出于安全的考虑,请把该文件删除
测试 PHP 的 oci
写一个简单的页面测试 oci 是否可用 (Just a copy sample from OTN):
$db_conn = ocilogon( "scott", "tiger","TEST" );
$cmdstr = "select ename, sal from emp";
$parsed = ociparse($db_conn, $cmdstr);
ociexecute($parsed);
$nrows = ocifetchstatement($parsed, $results);
echo " for ($i = 0; $i { } echo "
echo "Oracle PHP Test
";
echo "\n\
";\n"; \n";
echo "Name \nSalary \n
echo "\n"; \n";
echo "" . $results["ENAME"][$i] . " ";
echo "$ " . number_format($results["SAL"][$i], 2). " ";
echo " Number of Rows: $nrows
echo "
If you see data, then it works!
?>
说明:上例中,scott/tiger分别为数据库的用户名字和密码,TEST为数据库连接串名字。

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

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.
