0
votes

I'm not sure if this the correct place to be asking this question. But I am having trouble getting my cgi scripts to run on my XAMPP Server (using windows 8 and apache) here is my cgi script:

#!usr/bin/perl

use warnings;
use diagnostics;

use strict;

my $time = localtime;
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};
my $admin_email = $ENV{SERVER_ADMIN};

print <<END_OF_PAGE;
<HTML>
<HEAD>  
<TITLE>Welcome to Mike's Mechanics Database</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">  
<IMG SRC="/images/mike.jpg" ALT="Mike's Mechanics">  
<P>Welcome from $remote_host! What will you find here? You'll find a list of mechanics 
from around the country and the type of    service to expect -- based on user input and 
suggestions.</P>  
<P>What are you waiting for? Click <A HREF="/cgi/list.cgi">here</A>    
to continue.</P>  <HR>  <P>The current time on this server is: $time.</P>  
<P>If you find any problems with this site or have any suggestions,    
please email <A HREF="mailto:$admin_email">$admin_email</A>.</P>
</BODY>
</HTML>
END_OF_PAGE

and here is the full error I am getting:

**Server error! The server encountered an internal error and was unable to complete your request. Error message: couldn't create child process: 720002: welcome.cgi If you think this is a server error, please contact the webmaster. Error 500 localhost Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30

finally, here is the entries in the apache error log, corresponding to the problem

[Mon Aug 21 20:46:19.403512 2017] [cgi:error] [pid 1436:tid 1724] (OS 2)The system cannot find the file specified. : [client ::1:61381] couldn't create child process: 720002: welcome.cgi, referer: http://localhost/Perl/

[Mon Aug 21 20:46:19.404515 2017] [cgi:error] [pid 1436:tid 1724] (OS 2)The system cannot find the file specified. : [client ::1:61381] AH01223: couldn't spawn child process: C:/xampp/htdocs/Perl/welcome.cgi, referer: http://localhost/Perl/

2

2 Answers

3
votes

I see two problems.

  1. Your CGI script isn't actually CGI compliant -- it needs to output headers before the document body. Consider using the CGI module to handle some of this for you.

  2. You're missing a leading slash in the shebang. It should be #!/usr/bin/perl. (And make sure that Perl is actually installed at that path.)

1
votes

Please don't learn CGI programming in 2017. Take a look at CGI::Alternatives for a gentle introduction to some modern ways to write web programs in Perl.

Having said that, the solutions to your immediate problem are to:

  • Fix the shebang line in your code
  • Output the CGI header before your HTML.

I'm using the CGI module to produce the header. I've also updated your HTML to look like something that was written in the last ten years (lower-case tags, using CSS rather than presentation attributes, HTML5 doctype, indentation).

#!/usr/bin/perl

use strict;
use warnings;
use diagnostics; # Remove before putting into production

use CGI 'header';

my $time = localtime;
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};
my $admin_email = $ENV{SERVER_ADMIN};

print header;

print <<END_OF_PAGE;
<!DOCTYPE html>
<html>
  <head>
    <style type='text/css'>
body {
  background-color: #ffffff;
}
    </style>
    <title>Welcome to Mike's Mechanics Database</title>
  </head>
  <body>
    <img src="/images/mike.jpg" ALT="Mike's Mechanics">  
    <p>Welcome from $remote_host! What will you find here? You'll
      find a list of mechanics from around the country and the type
      of service to expect -- based on user input and  suggestions.</p>
    <p>What are you waiting for?
      Click <a href="/cgi/list.cgi">here</a> to continue.</p>
    <hr>
    <p>The current time on this server is: $time.</p>
    <p>If you find any problems with this site or have any 
      suggestions, please email
      <a href="mailto:$admin_email">$admin_email</a>.</p>
  </body>
</html>
END_OF_PAGE