我不确定这是否是提出这个问题的正确位置。但我无法让我的cgi脚本在我的XAMPP服务器上运行(使用Windows 8和apache)这里是我的cgi脚本:
#!usr/bin/perl
use warnings;
use diagnostics;
use strict;
my $time = localtime;
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};
my $admin_email = $ENV{SERVER_ADMIN};
print <<END_OF_PAGE;
<HTML>
<HEAD>
<TITLE>Welcome to Mike's Mechanics Database</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<IMG SRC="/images/mike.jpg" ALT="Mike's Mechanics">
<P>Welcome from $remote_host! What will you find here? You'll find a list of mechanics
from around the country and the type of service to expect -- based on user input and
suggestions.</P>
<P>What are you waiting for? Click <A HREF="/cgi/list.cgi">here</A>
to continue.</P> <HR> <P>The current time on this server is: $time.</P>
<P>If you find any problems with this site or have any suggestions,
please email <A HREF="mailto:$admin_email">$admin_email</A>.</P>
</BODY>
</HTML>
END_OF_PAGE
这是我得到的完整错误:
**服务器错误! 服务器遇到内部错误,无法完成您的请求。 错误信息: 无法创建子进程:720002:welcome.cgi 如果您认为这是服务器错误,请与网站管理员联系。 错误500 本地主机 Apache / 2.4.25(Win32)OpenSSL / 1.0.2j PHP / 5.6.30
最后,这是apache错误日志中的条目,对应于问题
[Mon Aug 21 20:46:19.403512 2017] [cgi:error] [pid 1436:tid 1724](OS 2)系统找不到指定的文件。 :[client :: 1:61381]无法创建子进程:720002:welcome.cgi,referer:http://localhost/Perl/
[Mon Aug 21 20:46:19.404515 2017] [cgi:error] [pid 1436:tid 1724](OS 2)系统找不到指定的文件。 :[client :: 1:61381] AH01223:无法生成子进程:C:/xampp/htdocs/Perl/welcome.cgi,referer:http://localhost/Perl/
答案 0 :(得分:3)
我看到两个问题。
您的CGI脚本实际上并不符合CGI - 它需要在文档正文之前输出标题。请考虑使用CGI模块为您处理部分内容。
你错过了shebang的一个主要斜线。它应该是#!/usr/bin/perl
。 (并确保Perl实际安装在该路径上。)
答案 1 :(得分:1)
请不要在2017年学习CGI编程。请查看CGI::Alternatives,了解一些在Perl中编写Web程序的现代方法。
话虽如此,您当前问题的解决方案是:
我正在使用CGI模块生成标题。我还更新了你的HTML看起来像过去十年写的东西(小写标签,使用CSS而不是表示属性,HTML5 doctype,缩进)。
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics; # Remove before putting into production
use CGI 'header';
my $time = localtime;
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};
my $admin_email = $ENV{SERVER_ADMIN};
print header;
print <<END_OF_PAGE;
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body {
background-color: #ffffff;
}
</style>
<title>Welcome to Mike's Mechanics Database</title>
</head>
<body>
<img src="/images/mike.jpg" ALT="Mike's Mechanics">
<p>Welcome from $remote_host! What will you find here? You'll
find a list of mechanics from around the country and the type
of service to expect -- based on user input and suggestions.</p>
<p>What are you waiting for?
Click <a href="/cgi/list.cgi">here</a> to continue.</p>
<hr>
<p>The current time on this server is: $time.</p>
<p>If you find any problems with this site or have any
suggestions, please email
<a href="mailto:$admin_email">$admin_email</a>.</p>
</body>
</html>
END_OF_PAGE