Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Yet Another Premature End of Script Headers Question

by Anonymous Monk
on Jul 19, 2005 at 16:23 UTC ( [id://476171]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm doing some development work on a Fedora box with Apache 2. For some reason, I can't get even the simplest CGI scripts to work. Any script that I try to execute through the web gives me "Premature end of script headers". I've checked the Apache error log, but it also only says "Premature end of script headers". I can run the scripts from the command line and they execute as expected. Any ideas? I typed the following script directly into emacs via ssh, so I'm pretty sure it isn't an issue of having hidden characters in my script.
#!/usr/bin/perl -w print "Content-type: text/html\n\n"; print "<HTML><HEAD>"; print "<TITLE>CGI Test</TITLE>"; print "</HEAD>"; print "<BODY><H2>Hello, world.</H2>"; print "</BODY></HTML>";

Thanks!

Replies are listed 'Best First'.
Re: Yet Another Premature End of Script Headers Question
by izut (Chaplain) on Jul 19, 2005 at 17:41 UTC
    I know it should be annoying, but did you chmod it? Did you try perl -c on shell? Does it run without problems?

    surrender to perl. your code, your rules.

Re: Yet Another Premature End of Script Headers Question
by brian_d_foy (Abbot) on Jul 19, 2005 at 21:33 UTC
Re: Yet Another Premature End of Script Headers Question
by gam3 (Curate) on Jul 19, 2005 at 17:21 UTC
    Have you tried running it from the command line as the ``WEB'' user. That is nobody or http (I can't remember which one it is off the top of my head).

    I would think that you would get a different error message if perl is just not running.

    -- gam3
    A picture is worth a thousand words, but takes 200K.

      The user Apache runs under is configurable, but I believe it defaults to nobody.


      They say that time changes things, but you actually have to change them yourself.

      —Andy Warhol

      I had tried running it as the web user, and that worked fine. I finally solved the problem. Apache was configured to use suEXEC, and suEXEC wasn't configured correctly.
Re: Yet Another Premature End of Script Headers Question
by Adam (Vicar) on Jul 19, 2005 at 17:35 UTC
    I would make CGI.pm do the header for you:
    use strict; use CGI; my $header = CGI->new()->header();
Re: Yet Another Premature End of Script Headers Question
by JediWizard (Deacon) on Jul 19, 2005 at 16:36 UTC

    I believe you need cariage return/new line combinations after the headers. Try:

    #!/usr/bin/perl -w print "Content-type: text/html\r\n\r\n"; print "<HTML><HEAD>"; print "<TITLE>CGI Test</TITLE>"; print "</HEAD>"; print "<BODY><H2>Hello, world.</H2>"; print "</BODY></HTML>";

    Also, might I recomend "use CGI"


    They say that time changes things, but you actually have to change them yourself.

    —Andy Warhol

      Don't confuse CGI output with network output. The CGI script's output is going to be fixed up by apache before it hits the network. The web server will take care of line endings and extra header information.

      For a simple script such as this one, you don't need CGI. You could use a heredoc though. :)

      #!/usr/bin/perl print <<"CGI"; Content-type: text/html <html> <head><title>CGI test</title></head> <body> <H2>Hello, world.</H2> </body> CGI
      --
      brian d foy <brian@stonehenge.com>
      I've tried it with \r\n\r\n as well, and it doesn't work. RE: CGI: yes, I use CGI in the actual applications that I'm trying to install, but I want to get the simplest case working first.

      I'm still left with the question of why nothing more shows up in the Apache error log.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://476171]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found