tags:

views:

48

answers:

2

I have a Perl script which is scripted to print "Hello!" on a web browser. I am using apache as my localhost server. The OS I am using is the Red Hat 5.

The problem is that when I type the address http://localhost/example.pl or http://127.0.0.1/example.pl, it shows me exactly the entire script codes but not the "Hello!" word that should be output.

The Perl script:

#!/usr/bin/perl

print "content-type: text/html \n\n";

print "Hello, Perl!";

Anyone has any ideas on this? Thanks!

A: 

You have to put it in cgi-bin

As you noticed, files that are not processed by the interpreter are returned as downloadable text files, therefore apache designates space where files will be interpreted/processed by the server (the common gateway interface bin).

First you have to set up apache to point to a cgi-bin directory - it does this by default, you can put your file there. Once your file is there the URI would be something like: http://localhost/cgi-bin/example.pl


Note: you cannot put html/js in the cgi-bin as they will be processed and will cause a server fault.

I recommend reading more from apache's website.

vol7ron
I made all the necessary changes to the conf file but its still not working. Now it tells me the error of "The requested URL /cgi-bin/example.pl was not found on this server.". Do you know where can I find the .htaccess file in Linux?
JavaNoob
Well, you don't have to put it in /cgi-bin/. You have to put it in somewhere that the webserver will recognize it as an executable file. You have to tell the webserver how to handle that.
brian d foy
A cgi-bin should have been created by default. You shouldn't need to touch the .htaccess file. Once you have it working in cgi-bin, you can use Redirect/RewriteRules to mask the path so `http://localhost/index.cgi -> http://localhost/cgi-bin/index.cgi`
vol7ron
A: 

The Apache docs tell you how to configure your webserver to run CGI programs in Apache Tutorial: Dynamic Content with CGI.

brian d foy