2010.5.4
1, 下载windows环境下的ActivePerl5.10(http://www.activestate.com/activeperl/);2, 双击ActivePerl-5.8.8.820-MSWin32-x86-274739.msi安装.安装目录位置为C:/perl,当然,你可以安装在任意你喜欢的目录,一路默认安装;3、C:盘下新建index.pl,用记事本打开,写上代码:#!C:/bin/perl.exe # 此句一定要写准确的安装路径;#scriptname index.pl print "Content-type: text/html/n/n"; # 此句一定要写而且写准确. print "Hello, World.../n"; 保存,在命令窗口执行 perl index.pl,看到成功运行的“hello world”,恭喜perl安装成功。3.配置Apache以支持CGI 打开httpd.conf,找到#ScriptAlias /cgi-bin/ “C:/Apache/cgi-bin/” ,在下面添加ScriptAlias /cgi-bin/ "D:/WAMP/www/cgi-bin/" AllowOverride All Options All Order allow,deny Allow from all AddHandler cgi-script .cgi .pl .exe 其中"D:/WAMP/www/cgi-bin/"是存放*.pl脚本的目录,把目录的访问权限都设为All。 在此,apache支持perl/cgi的环境就配置完整了. 4.将刚才创建的index.pl拷贝到D:/WAMP/www/cgi-bin/目录下,重启apache,运行可执行目录地址,如http://localhost,测试一下. 注意:当您浏览cgi程序出现500错误:错误内容可能是这样:Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.......一下几种可能:1、*.pl 没有以#!C:/perl/bin/perl.exe开头或perl路径指示错误。或者没有print "Content-type: text/html;/n/n"; 2、没有把目录的访问权限都设为All;3、没有指定ScriptAlias /cgi-bin/ "D:/WAMP/www/cgi-bin/"或AddHandler cgi-script .cgi .pl .exe 等;
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]-->
安装ActivePerl-5.8.8.817-MSWin32-x86-257965.msi,建议安装在C:/USR目录下,因为每个CGI程序文件第一行都要申明CGI解释程序的路径(#!/usr/bin/perl)。
2.运行regedit (需要重新启动计算机才能生效)
找到: HKEY_LOCAL_MACHINE/System/Currentcontrlset/Services/W3svc/Parameters/ScriptMap/ 目录
增加以下键值:
键名: ".cgi" 键值: "C:/USR/BIN/perl.exe %s %s"
键名: ".pl" 键值: "C:/USR/BIN/perl.exe %s %s"
3.打开“Internet 服务管理器”,选中“默认web站点”或者其它站点,打开它的“属性”窗口。选中“主目录”页,单击“应用程序设置”下的“配置”按钮后,在新窗口下单击“添加”按钮;在“可执行文件”中输入“C:/usr/bin/perl.exe %s %s”,在“扩展名”中输入“.cgi”,把"脚本引擎"打上勾,点击“确定”(亦可添加其他,如“.pl”等)。接着,选中“ISAPI筛选器”页,单击“添加”按钮;在“筛选器名称”中输入“cgi”,在“可执行文件”中输入“C:/usr/bin/PerlIS.dll”,点击“确定”。
4.编写测试程序:
文件test.cgi放在CGI-BIN这个目录下,代码如下
#!/usr/bin/perl
print "Content-type:text/html/n/n";
print "<TITLE>这是我的第一个程序</TITLE>";
print "哈!哈!哈!我成功啦!!!";
在浏览器地址栏中键入http://127.0.0.1/cgi-bin/test.cgi
如果在浏览器中显示:哈!哈!哈!我成功啦!!!你就成功了。
1, 下载windows环境下的ActivePerl5.10(http://www.activestate.com/activeperl/);
2, 双击ActivePerl-5.8.8.820-MSWin32-x86-274739.msi安装.安装目录位置为C:/perl,当然,你可以安装在任意你喜欢的目录,一路默认安装;
3、C:盘下新建index.pl,用记事本打开,写上代码:
#!C:/bin/perl.exe # 此句一定要写准确的安装路径;
#scriptname index.pl
print "Content-type: text/html/n/n"; # 此句一定要写而且写准确.
print "Hello, World.../n";
保存,
在命令窗口执行 perl index.pl,看到成功运行的“hello world”,恭喜perl安装成功。
3.配置Apache以支持CGI
打开httpd.conf,找到#ScriptAlias /cgi-bin/ “C:/Apache/cgi-bin/” ,在下面添加
ScriptAlias /cgi-bin/ "D:/WAMP/www/cgi-bin/"
<Directory "D:/WAMP/www/cgi-bin">
AllowOverride All
Options All
Order allow,deny
Allow from all
</Directory>
AddHandler cgi-script .cgi .pl .exe
其中"D:/WAMP/www/cgi-bin/"是存放*.pl脚本的目录,把目录的访问权限都设为All。
在此,apache支持perl/cgi的环境就配置完整了.
4.将刚才创建的index.pl拷贝到D:/WAMP/www/cgi-bin/目录下,重启apache,运行可执行目录地址,如http://localhost,测试一下.
注意:当您浏览cgi程序出现500错误:
错误内容可能是这样:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
......
一下几种可能:
1、*.pl 没有以#!C:/perl/bin/perl.exe开头或perl路径指示错误。
或者没有print "Content-type: text/html;/n/n";
2、没有把目录的访问权限都设为All;
3、没有指定ScriptAlias /cgi-bin/ "D:/WAMP/www/cgi-bin/"或AddHandler cgi-script .cgi .pl .exe 等;
祝你成功!