Apache Lounge



Forum Index Downloads Search Register Log in  RSS Apache Lounge

Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.



A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.

How to get .cgi and perl scripts to work with browser

Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner

View previous topic :: View next topic  
Author Message

Joined: 25 Jan 2014
Posts: 1
Location: Toronto

PostPosted: Sat 25 Jan '14 19:26    Post subject: How to get .cgi and perl scripts to work with browser Reply with quote


When running a .pl from the CMD I can get them to work but when using the "localhost/cgi-bin/(name of script here)" in the browser address bar all
I get is "Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request." with a "500 Internal Server Error" title in the
browser window.

How can I get the .cgi and .pl example scripts found online to load into a browser when using Apache?

If I go to "C:\Program Files\Apache Group\Apache2\cgi-bin" and right click a .pl file to have it opened with an internet browser, basically I get the script code in a browser window and I think that it is supposed to do more than that.

Here is an example of a script that I have used. The Apache HTTP Server 2.0 and Strawbery Perl have both been installed to their default settings.


## printenv -- demo CGI program which just prints its environment

print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";

which is the example included in Apache's install, or this one that I found online that works fine when running in CMD:


print "Enter your name: ";
print "Hello, ${name} ... you will soon be a Perl addict!";

Aren't theses scripts supposed to be as interactive as when they are opened in CMD when using Apache and Strawberry Perl on a localhost machine or am I supposed to have a html file that works with the scripts?

What I am trying to learn is how to create a feedback form for a site I am working on, so I am trying to get into it but am completely stumped of how this all works.
Back to top

Joined: 16 Oct 2007
Posts: 2101
Location: Sun Diego, USA

PostPosted: Mon 27 Jan '14 2:15    Post subject: Reply with quote

If perl is installed at C:\Perl64\bin\perl.exe, the first one should work fine running in Apache provided you have configured Apache correctly.

The second one won't work properly because it is asking for input from STDIN, it also would not work even if this wasn't the case because the first line of the script (the "shebang") is not pointing to the proper location that perl is installed to.

Now provided mod_cgi is loaded, the ScriptAlias line is properly pointing to Apach's cgi-bin folder, and down further the AddHandler cgi-script .cgi .pl is not commented out then the first should work.

So what you should have is:

LoadModule cgi_module modules/mod_cgi.so
ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache2/cgi-bin/"
AddHandler cgi-script .cgi .pl

You may also wish to add a ScriptLog, you can find out good info on failing scripts with it, it's not just a stab in the dark as it is without it.

ScriptLog logs/script-error.log
Back to top

Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1