WebFaction
Community site: login faq

Hello,

I am trying to use CGI scripts on my static host. We are getting a 500 error on the page, and when I check the logs it's a "premature end of script header" error, but I am fairly certain it is unrelated to the file permissions as I have set it to 711. Everything seems to be set up correctly because a simple "hello world" CGI script does work okay. Here is the code, any help/advice would be much appreciated:

#!/usr/bin/perl
# AUTHOR: Clifton Palmer
# DESCRIPTION: Demonstrates how to make a Perl CGI script that outputs HTML
# To generate HTML file on the fly, use command "perl test.cgi > test.html"
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;

# Dependency variables
my $script_jquery = 'jquery-1.6.1.min.js';
my $css_main = 'main.css';

# Page variables
my $title = "Clifton's Test Website";
my $email = 'clifton-palmer@uiowa.edu';
my $header_title = $title;

#-----------
# Main page
#-----------
print "Content-type: text/html\n\n";
print start_html(
        -title=>$title,
        -author=>$email,
        -style=>[
                { -type=>'text/css', -src=>$css_main }
        ],
        -script=>[
                { -type=>'text/javascript', -src=>$script_jquery }
        ]
        );

print<<HTML;

<!-- This is my main page template. One container to rule them all. -->
<div id="main">
        <p>Hello world!</p>
</div>
HTML

print end_html;

asked 18 Oct '11, 18:24

dmur
3113
accept rate: 0%

edited 19 Oct '11, 13:57


Your CGI script looks correct. One common source of error which would produce the 500 error (generally a premature end of script headers error), when it is not caused by permissions errors, is that of using non-Unix line endings. Can you confirm that your script is using Unix line endings?

If you are using DOS line endings, or Mac line endings, you can convert the script from within SSH using the commands:

dos2unix myscript.cgi
mac2unix myscript.cgi

Alternatively, when writing your script on another operating system and uploading it to the server via FTP, you can simply choose to use a unix-aware text editor and choose to save the file with Unix line endings. Hope that helps!

permanent link

answered 18 Oct '11, 19:16

ryans ♦♦
5.0k103760
accept rate: 43%

edited 18 Oct '11, 19:17

Thanks, that worked!

(19 Oct '11, 13:50) dmur
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×125
×31
×20

question asked: 18 Oct '11, 18:24

question was seen: 18,853 times

last updated: 19 Oct '11, 13:57

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM