1

I need small virtual machine with a Web server, so I decided to install Damn Small Linux. I need to run a Web server that is hosting a site with a script that checks for a server's IP address and returns it in a HTML page. So far I have something like this working:

Script file:

#!/usr/bin/perl

print "Content-type: text/html\n\n" ;
print <<EOF ;
<html>
<head><title>CGI Results</title></head>
<body>
<h1>Hello, world.</h1>
</body>
</html>
EOF
exit ;

The script is called from HTML like this:

<iframe src="http://localhost/cgi-bin/skrypt.cgi" width="100%"></iframe>

It's working fine, but whenever I add something to this script other than a print statement, for example:

my $address = "someValue"

… then the HTML page is not running the script but instead it is downloading it. What do I have to do to make this script work? I just need an IP address to appear on the Web page.

daxim
  • 39,270
  • 4
  • 65
  • 132
user964986
  • 125
  • 1
  • 2
  • 10
  • _Downloading it_ may be a matter of web server configuration instead. What webserver are you using? Does it need to be configured to not allow downloading of `cgi-bin/` content? – sarnold May 11 '12 at 23:55
  • From the [Stack Overflow Perl FAQ](http://stackoverflow.com/questions/tagged/perl?sort=faq): [How can I troubleshoot my Perl CGI script?](http://stackoverflow.com/questions/2165022/how-can-i-troubleshoot-my-perl-cgi-script) – daxim May 12 '12 at 14:56

1 Answers1

2

Try to run your cgi script in the command line:

perl -c my_script.cgi

and if it is ok, try to run using strict and warnings activated.

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;

If there is no problem, look into the error log.

Tiago Peczenyj
  • 4,387
  • 2
  • 22
  • 35