cgi脚本没有执行
我有一个 perl.cgi 文件,其内容如下:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";
我使其可执行。 (chmod a+x perl.cgi
)
然后我在同一目录中创建了一个新文件 perl.htm
。其中包含以下数据:
Content-type: text/html
<p><a href="perl.cgi">RUN perl.cgi</a></p>
当我在浏览器中运行 perl.htm
时,我得到的输出为:
Content-type: text/html
RUN perl.cgi
当我单击 RUN perl.cgi
时,会打开另一个页面并在那里输出是:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";
即 perl.cgi
没有执行。仅显示文件内容。
编辑:从答案和评论中我知道我必须配置我的网络服务器(apache)来运行cgi脚本。我怎样才能做到这一点?让我知道。
I have a perl.cgi
file which has the content:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";
I made it executable. (chmod a+x perl.cgi
)
Then I created a new file perl.htm
in the same directory. Which has the following data:
Content-type: text/html
<p><a href="perl.cgi">RUN perl.cgi</a></p>
When I run the perl.htm
in my browser then I get the output as:
Content-type: text/html
RUN perl.cgi
When I click on RUN perl.cgi
another page opens and there the output is:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";
i.e. the perl.cgi
is not executing. Only the file contents are being shown.
EDIT: From the answers and comments I came to know that I will have to configure my web server (apache) to run cgi scripts. How can I do that? Let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来 Apache 没有配置为运行 *.cgi 文件:
Sounds like Apache is not configured to run *.cgi files:
确保您正在 httpd.conf 文件中加载 CGI 模块:
LoadModule cgi_module module/mod_cgi.so
或LoadModule cgi_module module/mod_cgid.so
取决于您运行的 Apache 版本。您还可以阅读有关其他解决方案的信息
使用 CGI 的动态内容。
Make sure you are loading the CGI module in the httpd.conf file:
LoadModule cgi_module modules/mod_cgi.so
orLoadModule cgi_module modules/mod_cgid.so
depending on which version of Apache you are running.You can also read about additional solutions for
Dynamic Content with CGI.
问题已经解决了。我根本没有使用 httpd 服务,而是从 file:// URL 打开。
Perl 脚本未以 HTML 形式执行
Problem has been solved. I was not using httpd service at all, was opening from file:// URL.
Perl script is not executing in HTML form
您需要设置 Web 服务器,以便它执行 *.cgi 文件(或者更常见的是,执行特定目录中的所有文件),而不是像执行 .html 文件那样将它们传送到浏览器。
如何完成此操作取决于您的服务器。
You need to setup your web server so that it executes *.cgi files (or, more normally, all the files in a particular directory) rather than just delivering them to the browser as it does .html files.
How this is done depends on your server.