Table of Contents
Oracle PHP Test
Home php教程 php手册 整合Oracle 10g、Apache 2.0、Php 5

整合Oracle 10g、Apache 2.0、Php 5

Jun 06, 2016 pm 07:55 PM
apache oracle php Integrate

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 基本介绍 2004 年 7 月 13 日 , PHP 官方站点正式发布了 PHP 5 。 Oracle 在 2004 年 8 月宣布将在拳头产品 Application Server 中提供对 PHP 的支持。先是在 Oracle Application Server 10g ( 9.0

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入

基本介绍

2004713PHP 官方站点正式发布了 PHP 5Oracle 2004 8 月宣布将在拳头产品 Application Server 中提供对 PHP 的支持。先是在Oracle Application Server 10g (9.0.4) 提供 mod_php 模块,继而在Oracle Application Server 10g Release 2 (10.1.2) 中提供了 PHP 4.3的版本,接着Oracle JDeveloper 10g 也将提供对 PHP 扩展能力。相信,不久Oracle将正式支持 PHP 5。而随着 Oracle 技术社区的大力推广,也将有更多的开发人员利用 PHP 进行大型数据库引用的开发。

OTN 上已经有文档描述如何进行 10g / HTTPD 1.3/ PHP 4 的整合。所以这篇文档将描述如何整合 Oracle 10gApache (httpd 2)PHP 5。便于快速的组建一个开发环境。如果您想对 PHP 的一些新功能(比如PDO)进行一下体验,那么本文可以作为一个开端。

OracleApachePHP三者之间的关系不妨借用一下这张示意图(原图地址)

整合Oracle 10g、Apache 2.0、Php 5

 

本文假定您的 Oracle 10g (服务器或者客户端)已经安装完毕。如果没有安装,请参考这篇文档:

http://www.dbanotes.nethttp://oracle.chinaitlab.com/Install-Oracle10g-RHEL3.htm

确定自己的 Oracle 处于可用状态。

本文所拥的操作系统为 Fedora Core 3 LinuxOracle 版本为10 R1 (10.1.0.2)

下载所需文件:HTTPD PHP 5

HTTPD - httpd://httpd.apache.org (目前的版本是 2.0.52)

PHP 5 - http://www.php.net (最新版本是 5.0.2)

安装HTTPD

需要说明的是,现在 Apache 社区不推荐把 Apache 2.0 用在产品环境中.

[root@FC3 software]# tar -zxvf httpd-2.0.52.tar.gz
[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 start
[root@FC3 httpd-2.0.52]# /usr/local/apache/bin/apachectl stop

安装说明:第三行指定 Apache 的架构独立的文件安装位置。同时指定将用模块的形式。

如果为了方便的话,可以创建两个脚本控制 Apache 的启动与关闭。

[root@FC3 ~]# vi /bin/startapache

添加如下内容:

#!/bin/sh
ORACLE_HOME=/u01/app/oracle/product/10.1.0/db_1

ORACLE_SID=TEST
export ORACLE_HOME ORACLE_SID
echo Starting Apache
/usr/local/apache/bin/apachectl start

创建关闭 apache 的脚本:

[root@FC3 ~]# vi /bin/stopapache
添加如下内容:
#!/bin/sh
ORACLE_HOME=/u01/app/oracle/product/10.1.0/db_1

ORACLE_SID=TEST
export ORACLE_HOME ORACLE_SID
echo Starting Apache
/usr/local/apache/bin/apachectl stop
修改文件权限:
[root@FC3 ~] chmod +x /bin/startapache /bin/stopapache

安装 PHP 5

[root@FC3 software]# tar -xjf php-5.0.2.tar.bz2
[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-5.0.2]# vi /usr/local/apache/conf/httpd.conf

添加如下内容:

LoadModule php5_module modules/libphp5.so

     AddType application/x-httpd-php .php

重新启动 apache:
[root@FC3 ]# /bin/stopapache
[root@FC3 ]# /bin/startapache
测试 PHP 模块
测试 PHP 模块是否已经可用。当然是标准办法,写一个包含如下内容的PHP页面 info.php:

从浏览器中查看该页面输出内容。

注意,该页面中的内容 Configure Command 那一行中的内容是否包括如下内容:

'--with-apxs2=/usr/local/apache/bin/apxs'
'--with-oci8=/u01/app/oracle/product/10.1.0/db_1'

注意:在测试之后,出于安全的考虑,请把该文件删除

测试 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 "Oracle PHP Test";
echo "

Oracle PHP Test


";
echo "\n\\n";
echo "\n\n\n";

for ($i = 0; $i {
    echo "

\n";
    echo "
";
    echo "
";
    echo "
\n";

}

echo "

NameSalary
" . $results["ENAME"][$i] . "$ " . number_format($results["SAL"][$i],   2). "
Number of Rows: $nrows
";
echo "
If you see data, then it works!
\n";

?>

说明:上例中,scott/tiger分别为数据库的用户名字和密码,TEST为数据库连接串名字。

整合Oracle 10g、Apache 2.0、Php 5

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

Video Face Swap

Video Face Swap

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

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)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

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.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

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's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

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 in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

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 and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

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: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

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: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

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.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

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.

See all articles