Perl CGI


#1

Hi there,
I am new to dreamhost and to perl CGI too, but I want to give it a try.

Unfortunately I am getting only an “Internal Server Error”. The error.log speaks about “Premature end of script headers”.
Can anyone help me with this?

What I did in detail:
I created a folder cgi-bin in my domain-dir, placed a small test script in it
8<---- test.pl
#!/usr/bin/perl
print “

Hello

\n”;
8<----

chmod 755 -R cgi-bin

whereis perl

tells me /usr/bin/perl

./test.pl

works fine

In this forum and the wiki I found many people having problems with access rights, so I did a chmod 777 on the files, but this didn’t do the trick.

Greetings


#2

[quote]I created a folder cgi-bin in my domain-dir, placed a small test script in it
8<---- test.pl
#!/usr/bin/perl
print “

Hello

\n”;
8<----

chmod 755 -R cgi-bin

whereis perl

tells me /usr/bin/perl

./test.pl

works fine

In this forum and the wiki I found many people having problems with access rights, so I did a chmod 777 on the files, but this didn’t do the trick.[/quote]
Here is what happens when your run a CGI script:

  1. The web server sets up a “CGI environment” and then executes the script.
  2. The “perl” program runs your script
  3. The web server expects the script output to start with headers followed by a blank line followed by the content to pass along to the web browser.

From the error message you can tell that the failure is with step #2 or step #3. From your code, it is apparent that it is at least step #3 - you did not output a set of headers.

At the minimum you need a Content-Type header. Observe.

$mime_type = ‘text/html’;
$header_content_type = “Content-Type: $mime_type\n”;
@headers = ($header_content_type);
$blank_line = “\n”;
$content = “

Hello

\n”;

print
@headers,
$blank_line,
$content;

The reason you get “premature end of headers” messages is because the output the web server sees is not a set of headers. Other than skipping the headers like your script does, you can also get this message if the perl program has a problem interpreting your code (syntax errors, etc) or crashing.

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#3

Thanks for your quick reply, but your script did not work either. The output is the same. The logfile says:
8<— error.log
suexec policy violation: see suexec log for more details
Premature end of script headers: test3.pl
8<—

Here is your script I used:
8<—test3.pl
#!/usr/bin/perl
$mime_type = ‘text/html’;
$header_content_type = “Content-Type: $mime_type\n”;
@headers = ($header_content_type);
$blank_line = “\n”;
$content = “

Hello

\n”;
print
@headers,
$blank_line,
$content;
8<—

I did a chmod 775 test3.pl before running it.

Running it in a terminal works fine:
8<—
Content-Type: text/html

Hello

8<---

Any further ideas?


#4

I found the solution, it was a stupid problem:

First thing is that Atropos7 was right about the header:
Content-Type: text/html
is necessaray.

The second problem was that the permissions have to be set to 755 instead of 775, as can be found in the wiki:

[quote]suexec requires that all cgi scripts and the directories
in which they reside not be writable by anyone but the owner

[/quote]

Thanks to Craig@DH for making me checking the wiki again!