Re: more apache/perl problems, "premature end of script" (SOLVED)
thanks to everyone who's helped out on this. especially Will Trillich
<will@serensoft.com> for pointing me to perl.apache.org. wow. =)
in any case. for posterity. in a stock apache-perl install on a
potato, you have to add something like the following to access.conf:
<Files ~ "\.pl$">
SetHandler perl-script
PerlHandler Apache::Registry
PerlSendHeader On
Options ExecCGI
</Files>
a good resource is also the man page on going from cgi to perl
(cgi_to_mod_perl).
*sigh* it feels good to get it to work. =) thanks again everyone!
herbert
On Mon, Nov 27, 2000 at 02:59:09PM -0600, will trillich wrote:
> welcome to the club, you've been initiated.
>
> On Mon, Nov 27, 2000 at 10:34:40AM -0600, Herbert Ho wrote:
> > i downloaded cgi-lib.pl and placed it in the same directory as my
> > script. (from cgi-lib.berkeley.edu) it runs fine on the cmdline (both
> > my box and my university's server)
> >
> > the error i get in /var/log/apache/error.log is (without the time
> > stamp):
> >
> > Premature end of script headers: /home/herb/public_html/init/login.pl
> >
> > what changes have to be made to a stock apache config on potato for
> > cgi/perl to work in the user public_html directories?
>
> apache, when it runs a process that generates the stuff that'll
> be sent out to a client's browser, checks the text for
> completeness. this includes all the header fields, such as
>
> content-type: text/html
> connection: close
> date: 27 nov 2000
> accept-ranges: bytes
>
> try this, now:
>
> telnet localhost 80 ^M
> GET / HTTP/1.1 ^M
> ^M
>
> <localhost> is whatever host your server's running on;
> the ^M merely denotes end-of-line/enter on your part.
>
> here's what you'll get back:
>
> HTTP/1.1 200 OK
> Date: yada-yada
>
> that first line is the STATUS for the whole request,
> which comes even before the header:value fields.
>
> so try this in your script:
>
> #!/usr/bin/perl
> print "HTTP/1.1 200 OK\nContent-Type: text/html\n\n";
> print "<b>hello world</b><p>it worked!";
>
> so what you're seeing is APACHE noticing that you
> didn't specify a HTTP STATUS CODE.
>
> from the perl.apache.org/guide/ website--
>
> If you take a basic CGI script like this:
>
> print "Content-type: text/plain\r\n\r\n";
> print "Hello world";
>
> it wouldn't work, because the HTTP header will not be sent
> out. By default, mod_perl does not send any headers itself.
> You may wish to change this by adding
>
> PerlSendHeader On
>
> in the Apache::Registry <Location> section of your
> configuration. Now, the response line and common headers
> will be sent as they are by mod_cgi. Just as with mod_cgi,
> PerlSendHeader will not send the MIME type and a terminating
> double newline. Your script must send that itself
>
> the modperl guide (perl.apache.org/guide) offers a wealth of
> info, once you know what you're looking for... :)
>
> > the changes i've made so far:
> >
> > 1) in access.conf (adding ExecCGI to the Options directive in the
> > DirectoryMatch directive for the public_html directories)
> >
> > 2) in srm.conf (adding AddHandler cgi-script .pl .cgi)
> >
> > ## my script works in /usr/lib/cgi-bin/ but not in the public_html
> > directories. i've tried copying the Directory directive for
> > /usr/lib/cgi-bin word for word to the public_html directive w/ no
> > effect.
>
> you need
> # something along the lines of...
> LoadModule userdir_module /usr/lib/apache/1.3/mod_userdir.so
> UserDir /home/*/public_html
> <DirectoryMatch ^/home/.*/public_html/cgi-bin>
> Options +ExecCGI
> </DirectoryMatch>
> UserDir disabled root
> somewhere in your config, then.
>
> > thanks for everyone's help so far. i'm gonna get this to
> > work...somehow. =)
Reply to: