Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cgi script is not executing

Tags:

cgi

perl

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.

like image 925
Chankey Pathak Avatar asked Nov 29 '22 03:11

Chankey Pathak


2 Answers

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

AddHandler cgi-script cgi pl
<Directory /path/to/cgi/files>
    Options +ExecCGI
</Directory>
like image 63
Gabriel Ross Avatar answered Dec 05 '22 07:12

Gabriel Ross


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.

like image 27
yellavon Avatar answered Dec 05 '22 05:12

yellavon