2
votes

How do I run perl script from local host?

I have installed Apache 2.2 and Active Perl 5.16.3. I am able to run the perl scrip from command prompt. But since i am dealing with web application, i want it to be run from localhost.

However, I am getting the following error in the browser

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.

Please help me out!

3
There should be more details in the server's error log. - cjm
What does your script look like? - user149341

3 Answers

0
votes

Your problem is probably related to the configuration of Apache. (It may be Apache that needs configuring for .cgi scripts) - If this is the case then you can find good info on this here:

http://www.perlmonks.org/?node_id=44536
http://www.cgi101.com/book/connect/winxp.html
http://www.editrocket.com/articles/perl_apache_windows.html

There is usually a host of things that you need to do to get it working. Following a good HOWTO to make sure that everything is installed and configured correctly will usually get you going to execute scripts on your local Windows machine.

0
votes

You could run cgi script from web browser. CGI means that it should send a HTML header before sending any output to the server (which is going to send it back to the browser).

http://perldoc.perl.org/CGI.html#NAME

http://www.cs.tut.fi/~jkorpela/perl/cgi.html

Like this:

use CGI; # load CGI routines
$q = CGI->new; 
print $q->header; # create the HTTP header
print $q->start_html('hello world'); # start the HTML

### your script logic goes here

print $q->end_html; # end the HTML

Of course, CGI is outdated, for new development you should use some mmore recent framwork like: Dancer, Mojolicious, ...

0
votes

if someone is looking for an answer in year 2017 then follow this on windows 2010 machine.

  1. Download Strawberry perl from perl site Install in default directory.C:\Strawberry

  2. Download Apache from https://httpd.apache.org/download.cgi#apache24

  3. Once you successfully get apache server running then

  4. Place your perl scripts in your Apache24/cgi-bin/ folder. firstline of your perl script should point to path where perl is installed for my case it is #!C:/Strawberry/perl/bin/perl.exe you should change your path according your installation folder

Filename - first.pl

#!C:/Strawberry/perl/bin/perl.exe
print "Content-type: text/html\n\n";
print "Hello, World.";
  1. Now you can run your script from browser http://localhost/cgi-bin/first.pl