歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Linux資訊 >> Linux文化

如何集成Linux/Apache/PHP4/FastCGI/Oracle/MySQL環境


一. 准備工作
要實現將以上環境集成,必需先准備好以下軟件包:

(一)數據庫的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詳細參見<Oracle 8.1.6安裝HOWTO>
在此簡單列出操作過程:

(一)設置環境變量:
在/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"
<Directory "/home/httpd/html">
Options Indexes FollowSymLinks MultiViews Includes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "/home/httpd/cgi-bin/"
<Directory "/home/httpd/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
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
<Location /fcgi>
SetHandler fastcgi-script
Order deny,allow
Allow from all
Options ExecCGI Indexes Includes
</Location>
############### 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
內容:
<? phpinfo() ?>
第二個測試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\n\n";
print "<html><body>\n";
if (!$dbh){
print "no oracle, need to connect<br>\n";
$dbh = DBI->connect("dbi:Oracle:$dbname",$user,$passwd);
}else{
print "OK, oracle aleady connected<br>\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] <br>\n";
print "參數para=".$para."<br>\n</html>";
}
####傳入參數處理部分#######
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/<!--(.|\n)*-->//g;

if ($allow_html != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
$FORM{$name} = $value;
}
}
測試看看FastCGI是否正常執行了


- 張宏 ([email protected]


Copyright © Linux教程網 All Rights Reserved