4

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.

2
  • You need to describe your web server setup in far more detail. Commented Sep 19, 2011 at 13:40
  • 1
    Voted to move to serverfault.com but ... try renaming the file to 'perl.pl'. If that's not it you need to configure your webserver corectly for executing perl cgi Commented Sep 19, 2011 at 13:42

4 Answers 4

10

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

AddHandler cgi-script cgi pl <Directory /path/to/cgi/files> Options +ExecCGI </Directory> 
Sign up to request clarification or add additional context in comments.

4 Comments

Done, still having the same problem
I am still unable to run cgi. Please help.
@Chankey Pathak have you read the documentation? Apache configuration is hairy, it pays off to study it in detail.
Chankey Pathak: What error is in log files? If you copied it from Windows, fif you transfer it in text mode?
8

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.

Comments

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

Comments

0

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.

2 Comments

I am using apache. How can I configure it to be able to run cgi?
See the answer from @Gabriel and maybe add ScriptAliasMatch ^/cgi-bin(.*) "/full/path/to/cgi/directory/$1" in your <IfModule alias_module> section

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.