一. 准备工作
要实现将以上环境集成,必需先准备好以下软件包:
(一)数据库的perl接口
1.perl5的oracle数据库dbi驱动程序:dbd-oracle-1.03.tar.gz
2.perl5的通用数据库接口程序:dbi-1.13.tar.gz
3.perl5的mysql数据库dbi驱动程序:msql-mysql-modules-1.2209.tar.gz
(二)oracle数据库
4.oracle 8ir2(8.1.6) for linux安装盘:oracle8161.tar.gz
(三)mysql数据库
5.mysql 3.22.32服务器程序包:mysql-3.22.32-1.i386.rpm
6.mysql客户端程序包:mysql-client-3.22.32-1.i386.rpm
7.mysql开发包(头文件/库文件):mysql-devel-3.22.32-1.i386.rpm
8.mysql共享库程序包:mysql-shared-3.22.32-1.i386.rpm
(三)apache服务器
9.apache 1.3.12源码包:apache_1.3.12.tar.gz
(四)php模块
10.php 4.0.0源码包:php-4.0.0.tar.gz
(五)fastcgi模块
11.fastcgi模块源码包:mod_fastcgi_2.2.4.tar.gz
12.fastcgi的perl开发模块:fcgi-0.53.tar.gz
二. 安装oracle客户端
由于oracle 8.1.6是在xwindows下安装的,所以必须是事先配置好xwindow,如果你的
显卡不支持xwindow,也可以用exceed进行远程安装(这里不提远程如何安装).
安装oracle 8.1.6 for linux详细参见
在此简单列出操作过程:
(一)设置环境变量:
在/etc/profile中加入:
export oracle_home=/opt/oracle8i/u01
export oracle_base=/opt/oracle8i
export oracle_owner=oracle
export oracle_sid=orcl
export oracle_term=ansi
export path=$path:$oracle_home/bin
export ld_library_path=$oracle_home/lib
export ora_nls33=$oracle_home/ocommon/nls/admin/data
export nls_lang="simplified chinese_china.zhs16cgb231280"
(二)建立oracle组和用户
#/usr/sbin/groupadd dba
#/usr/sbin/useradd -g dba oracle
#/usr/bin/passwd oracle
(三)创建$oracle_home目录
#mkdir /opt
#mkdir /opt/oracle8i
#mkdir /opt/oracle8i/u01
#chown -r oracle.dba /opt
(四)安装reacle 8ir2
以oracle用户登录,解开oracle安装包:
$tar zxvf oracle8161.tar.gz
$startx 启动xwindow界面,并打开一个rxvt终端窗口
$cd oracle8ir2
$./runinstaller
此时出现oracle安装界面,在安装时选择安装client/application user
(如果oracle服务器不在本机上运行,另有专用机器),安装完毕后配置sql.net8并
测试连接远程服务器通过即可.
三. 安装mysql服务器和客户端
以root身分进入,安装mysql各个包:
#rpm -ivh mysql-3.22.32-1.i386.rpm
#rpm -ivh mysql-client-3.22.32-1.i386.rpm
#rpm -ivh mysql-devel-3.22.32-1.i386.rpm
#rpm -ivh mysql-shared-3.22.32-1.i386.rpm
四. 安装perl的数据库接口模块
以root身分进入,然后执行:
#tar zxvf dbi-1.13.tar.gz
#cd dbi-1.13
#perl makefile.pl
#make
#make test
#make install
#cd ..
#rm -rf dbi-1.13
#
#tar zxvf dbd-oracle-1.03.tar.gz
#cd dbd-oracle-1.03
#perl makefile.pl
#make
#make test
#make install
#cd ..
#rm -rf dbd-oracle-1.03
#
#tar zxvf msql-mysql-modules-1.2209.tar.gz
#cd msql-mysql-modules-1.2209
#perl makefile.pl
选择1(mysql)和y(支持mysql.pm)
#make
#make test
#make install
#
五. 安装apache+php+fastcgi
(一)解开apache/php/fastcgi包:
#tar zxvf apache_1.3.12.tar.gz
#tar zxvf php-4.0.0.tar.gz
#tar mod_fastcgi_2.2.4.tar.gz
(二)编译php4
配置apache编译参数
#cd apache_1.3.12
#./configure --prefix=/usr/local/apache
配置php编译参数
#cd ../php-4.0.0
#./configure --with-apache=../apache_1.3.12
> --with-mysql
> --with-oracle=$oracle_home
> --with-oci8=$oracle_home
> --enable-track-vars
编译php模块:
#make
#make install
创建php.ini参数文件
#cp php.ini-dist /usr/local/lib/php.ini
#cd ..
(三)添加fastcgi模块:
#mv mod_fastcgi_2.2.4 apache_1.3.12/src/modules/fastcgi
(四)编译安装apache
#cd apache_1.3.12
配置编译参数
#./configure --prefix=/usr/local/apache
> --activate-module=src/modules/php4/libphp4.a
> --activate-module=src/modules/fastcgi/libfastcgi.a
编译apache
#make
安装apache
#make install
(五)关闭原有系统自带的apache
#/etc/rc.d/init.d/httpd stop
(六)配置apache自身参数:
1.编辑/usr/local/apache/conf/httpd.conf文件,修改以下参数:
servername host.mydomain.name
documentroot "/home/httpd/html"
options indexes followsymlinks multiviews includes
allowoverride none
order allow,deny
allow from all
scriptalias /cgi-bin/ "/home/httpd/cgi-bin/"
allowoverride none
options none
order allow,deny
allow from all
directoryindex index.html index.phtml index.php index.htm index.shtml index.fcgi
2.修改自启动链接
#cd /etc/rc.d/init.d
#ln -fs /usr/local/apache/bin/apachectl httpd
(七)配置php4.0参数:
1.修改/usr/local/apache/conf/httpd.conf文件,修改以下参数:
增加一行:
addtype application/x-httpd-php .php .phtml .php3
2.修改/usr/local/apache/bin/apachectl脚本,使启动支持中文oracle环境:
在文件中66行("start)")下面加入几行:
export oracle_home=/opt/oracle8i/u01
export oracle_base=/opt/oracle8i
export oracle_sid=orcl
export ld_library_path=$oracle_home/lib
export ora_nls33=$oracle_home/ocommon/nls/admin/data
export nls_lang="simplified chinese_china.zhs16cgb231280"
3.修改/usr/local/apache/conf/srm.conf以在cgi程序中使用环境变量:
passenv oracle_home
passenv oracle_base
passenv ld_library_path
passenv nls_lang
passenv oracle_sid
passenv path
(八)配置fastcgi执行环境:
1.修改/usr/local/apache/conf/httpd.conf文件,修改以下参数:
增加几行:
############ fastcgi configures begin ##########################
addhandler fastcgi-script .fcg .fcgi .fpl
sethandler fastcgi-script
order deny,allow
allow from all
options execcgi indexes includes
############### fastcgi configure end ###########################
2.创建fcgi的执行目录
#mkdir /home/httpd/html/fcgi
3.安装fcgi的perl运行模块:
#tar zxvf fcgi-0.53.tar.gz
#cd fcgi-0.53
#perl makefile.pl
#make
#make install
六.启运并测试
1.启动apache服务器:
#/etc/rc.d/init.d/httpd start
2.编写php测试程序:
第一个测试程序:/home/httpd/html/t1.php
内容:
第二个测试php与oracle连接的php程序(表已经建好):
$conn=ocilogon("username","password","dblink");
$stmt=ociparse($conn,"insert into testtable (name,id) values ('中文测试',15)");
ociexecute($stmt);
$stmt=ociparse($conn,"select name from testtab where id=15");
ocidefinebyname($stmt,"name",&$nick);
ociexecute($stmt);
ocifetch($stmt);
echo "my name is $nick";
?>
查看是否为中文输出
第三个测试php与mysql连接的php程序(表已经建好):
$conn=mysql_connect("host","username","password");
mysql_query("insert into testtable (name,id) values ('中文测试',15)");
$result=mysql_query("select name from testtab where id=15");
$query_data=mysql_fetch_row($result);
$nick=$query_data[0];
echo "my name is $nick";
?>
3. 编写fastcgi的测试代码: /home/httpd/html/fcgi/test.fcgi
#!/usr/bin/perl
use fcgi;
use dbi;
$dbname="oracle";
$user="user";
$passwd="password";
$dbh="";
while(fcgi::accept()>=0) {
&parse_form();
$id=$form{'id'};
$para=$form{'para'};
print "content-type: text/htmlnn";
print "n";
if (!$dbh){
print "no oracle, need to connect
n";
$dbh = dbi->connect("dbi:oracle:$dbname",$user,$passwd);
}else{
print "ok, oracle aleady connected
n";
}
$sth=$dbh->prepare("select name from testtable where id=15");
$sth->execute;
@recs=$sth->fetchrow_array;
$sth->finish;
print "参数id=".$id." and my name is @recs[0]
n";
print "参数para=".$para."
n";
}
####传入参数处理部分#######
sub parse_form {
my($buffer);
my($pairs);
my(@pairs);
my($name);
my($value);
my $meth = $env{'request_method'};
if ($meth eq 'get' $meth eq 'head') {
$buffer = $env{'query_string'};
}
elsif ($meth eq 'post') {
read(stdin, $buffer, $env{'content_length'});
}
undef %form;
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fa-f0-9][a-fa-f0-9])/pack("c", hex($1))/eg;
$value =~ s/ //g;
if ($allow_html != 1) {
$value =~ s/<([^>]n)*>//g;
}
$form{$name} = $value;
}
}
测试看看fastcgi是否正常执行了
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器