Windows 环境下apache mod_perl activeperl安装运行说明

来源:岁月联盟 编辑:zhu 时间:2009-03-03

  1.下载并安装Perl-5.8-win32-bin.exe及近似版本;

  2.安装apache 2.0以上版本

  3通过命令行安装mod_perl,命令如下:

  C:> ppm install http://theoryx5.uwinnipeg.ca/ppms/mod_perl.ppd

  4,更改apache配置文件conf/ httpd.conf

   在loadmodule处添加如下两行:

  LoadFile "c:/perl/bin/perl58.dll"

  LoadModule perl_module modules/mod_perl.so

  在配置文件最后添加:

Alias /perl/ "c:/perl/"
PerlModule ModPerl::Registry
<Location /perl>
  SetHandler perl-script
  PerlHandler ModPerl::Registry
  Options ExecCGI
  allow from all
  PerlSendHeader On
</Location>

  此处"c:/perl/"为activeperl的安装目录,建议安装在盘符根目录下。

  <!--[if !supportEmptyParas]--> <!--[endif]-->

  然后重起apache,就可以在c:/perl目录下编写自己的perl CGI程序了。

<!--[if !supportEmptyParas]--> <!--[endif]-->
E.g.:hello.pl
#!/usr/bin/perl
use strict;
use CGI;
my $query = new CGI;
print $query->header;
print $query->start_html(-title=>"show hello");
print "<h1>";
print "hello,world!!";
print "</h1>";
print $query->end_html;
exit(0);
<!--[if !supportEmptyParas]--> <!--[endif]-->
<!--[if !supportEmptyParas]--> <!--[endif]-->

  template模块windows环境下的安装及测试如下:

  1命令行安装:

  ppm2 install http://theoryx5.uwinnipeg.ca/ppms/Apache-Template.ppd

  或者使用ppm,(just test it!)

  2创建template.pl于c:/perl下:

<!--[if !supportEmptyParas]--> <!--[endif]-->
use Template;
<!--[if !supportEmptyParas]--> <!--[endif]-->
my ($type) = "text/html; charset=gbk";
print "Content-type: ", $type, "
";
<!--[if !supportEmptyParas]--> <!--[endif]-->
my $config = {
  INCLUDE_PATH => 'C:/test',
  EVAL_PERL  => 1,
};
<!--[if !supportEmptyParas]--> <!--[endif]-->
my $template = Template->new($config);
<!--[if !supportEmptyParas]--> <!--[endif]-->
my $replace = "要放入模板的變數";
my $vars = {
  var => $replace,
};
<!--[if !supportEmptyParas]--> <!--[endif]-->
my $temp_file = 'template.html';
my $output;
$template->process($temp_file, $vars, $output)
  || die $template->error();
<!--[if !supportEmptyParas]--> <!--[endif]-->
print $output;
<!--[if !supportEmptyParas]--> <!--[endif]-->

  创建template.html于c:/test下

<html>
 <head>
  <title>Arthur Dent: Greet the Planet</title>
 </head>
 <body>
   dfsdf [% var %]
 </body>
</html>
<!--[if !supportEmptyParas]--> <!--[endif]-->

  这样我们就可以在浏览器中输入:http://localhost/perl/template.pl来测试我们的程序。

  <!--[if !supportEmptyParas]--> <!--[endif]-->

  <!--[if !supportEmptyParas]--> <!--[endif]-->

  <!--[if !supportEmptyParas]--> <!--[endif]-->

  <!--[if !supportEmptyParas]--> <!--[endif]-->