Perl + Apache + CGI



如何从本地主机运行perl脚本?

我已经安装了Apache 2.2和Active Perl 5.16.3。我能够从命令提示符运行 perl scrip。但是由于我正在处理 Web 应用程序,我希望它从本地主机运行。

但是,我在浏览器中收到以下错误

内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。

请帮帮我!

您的问题可能与 Apache 的配置有关。(可能是 Apache 需要为 .cgi 脚本进行配置) - 如果是这种情况,那么您可以在此处找到有关此的好信息:


http://www.perlmonks.org/?node_id=44536
http://www.cgi101.com/book/connect/winxp.htmlhttp://www.editrocket.com/articles/perl_apache_windows.html

您通常需要做很多事情才能使其正常工作。遵循一个好的 HOWTO 以确保所有内容都正确安装和配置通常会让您在本地 Windows 计算机上执行脚本。

您可以从Web浏览器运行cgi脚本。CGI意味着它应该在将任何输出发送到服务器之前发送一个HTML标头(服务器会将其发送回浏览器)。

http://perldoc.perl.org/CGI.html#NAME

http://www.cs.tut.fi/~jkorpela/perl/cgi.html

喜欢这个:

use CGI; # load CGI routines
$q = CGI->new; 
print $q->header; # create the HTTP header
print $q->start_html('hello world'); # start the HTML
### your script logic goes here
print $q->end_html; # end the HTML

当然,CGI已经过时了,对于新的开发,您应该使用一些最近的框架,例如:舞者,Mojolicious,...

如果有人在2017年寻找答案,请在Windows 2010机器上进行操作。

  1. 从 perl 网站下载 Strawberry perl在默认目录中安装。C:\草莓

  2. 从 https://httpd.apache.org/download.cgi#apache24 下载 Apache

  3. 一旦你成功地让 apache 服务器运行,那么

  4. 将 perl 脚本放在 Apache24/cgi-bin/文件夹中。你的Perl脚本的第一行应该指向安装Perl的路径,在我的情况下它是#!C:/草莓/perl/bin/perl.exe您应该根据安装文件夹更改路径

文件名 - first.pl

#!C:/Strawberry/perl/bin/perl.exe
print "Content-type: text/htmlnn";
print "Hello, World.";
  1. 现在,您可以从浏览器运行脚本 http://localhost/cgi-bin/first.pl

最新更新