一. 准备工作
要实现将以上环境集成,必需先准备好以下软件包:
(一)数据库的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/html ";
print " ";
if (!$dbh){
print "no oracle, need to connect
";
$dbh = DBI->connect("dbi:Oracle:$dbname",$user,$passwd);
}else{
print "OK, oracle aleady connected
";
}
$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]
";
print "参数para=".$para."
";
}
####传入参数处理部分#######
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/<([^>]| )*>//g;
}
$FORM{$name} = $value;
}
}
测试看看FastCGI是否正常执行了