cgi script is not executing

Deadly 提交于 2019-12-07 17:55:07

问题


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.


回答1:


Sounds like Apache is not configured to run *.cgi files:

AddHandler cgi-script cgi pl
<Directory /path/to/cgi/files>
    Options +ExecCGI
</Directory>



回答2:


Make sure you are loading the CGI module in the httpd.conf file:

LoadModule cgi_module modules/mod_cgi.so or LoadModule 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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/7471859/cgi-script-is-not-executing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!