Perl + Apache + CGI

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

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

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

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

请帮帮我!

你的问题可能与Apache的配置有关。 (可能是需要配置.cgi脚本的Apache) – 如果是这种情况,那么你可以在这里找到更好的信息:

http://www.perlmonks.org/?node_id=44536
http://www.cgi101.com/book/connect/winxp.html
http://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已经过时了,对于新的开发,你应该使用一些最近的框架,比如:Dancer,Mojolicious,…

如果有人在2017年寻找答案,那么在windows 2010机器上遵循这个。

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

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

  3. 一旦你成功运行Apache服务器然后

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

文件名 – first.pl

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