Re: Infamous "Premature end of script headers"
by NetWallah (Canon) on Dec 14, 2021 at 17:49 UTC
|
"perl scripts do not work" is a very poor problem description.
Are you saying you see nothing output in the browser ?
Have you checked the web-server logs for error message ?
You do say " "Premature end of script headers" in he title - that indicates header problem - but your headers appear correct.
There are plenty of pitfalls trying to get your first CGI script to work - you have the right approach by printing headers first - but you need to check - are the scripts getting loaded by the web server ? executable ? cgi framework loaded ?
The answers are in the web server error logs.
UPDATE: - Looks like you are missing the shebang line.
Here is a working script:
#!/usr/bin/perl
print "Content-Type: text/html;\n\n";
print "<h1>Hello, cgi world</h1>";
print "<table>\n";
print qq|<tr><td><b>$_</b> </td><td> $ENV{$_}</td></tr>\n| for sort ke
+ys %ENV;
print "</table>\n";
"If you had better tools, you could more effectively demonstrate your total incompetence."
| [reply] [d/l] |
Re: Infamous "Premature end of script headers" (FAQ)
by Anonymous Monk on Dec 14, 2021 at 22:03 UTC
|
| [reply] |
Re: Infamous "Premature end of script headers" -- -nph
by Discipulus (Canon) on Dec 15, 2021 at 08:07 UTC
|
Hello nato144,
welcome back to 2000 :)
While I'd suggest to abandon CGIs and move to PSGI aware technologies, I remember there was a nph directive for CGIs as you can see at cgifaq.2.html#6: did you tried it too?
See also USING-NPH-SCRIPTS
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
| [reply] [d/l] [select] |
Re: Infamous "Premature end of script headers"
by natol44 (Sexton) on Dec 16, 2021 at 20:02 UTC
|
Well finally I solved it by disabling suexec for the concerned virtualhost. It is a Centos8/Virtualmin problem.
I will anyway follow your recommendations and have a look at mod_perl.
Thank you to all!
| [reply] |
Re: Infamous "Premature end of script headers"
by Anonymous Monk on Dec 16, 2021 at 13:43 UTC
|
You need to read the server error logs. They should contain the STDERR from the script, including the reason for the failure. | [reply] |
Re: Infamous "Premature end of script headers"
by natol44 (Sexton) on Dec 15, 2021 at 19:37 UTC
|
Thank you for all replies, recommending me to try other options. The point is that the same script WORKS when ran by root (in a cron task) and fails when ran in the browser. Permission is 755 to be run in the browser).
I would like to understand what's going wrong with this :) | [reply] |
|
problem is: "run in the browser" is usually "run on server, wrapped in requests and responses from and to the browser", i.e.
-
browser sends request to server
-
server runs script
-
server sends response back
-
Browser renders response
and if it "fails/does not work", you have to find out which of these four steps is at fault, and decompose that further...
| [reply] |
|
| [reply] |
|
| [reply] |
|
I would like to understand what's going wrong with this :)
;) time to get started, the list is not long
| [reply] |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Re: Infamous "Premature end of script headers"
by vincent_veyron (Beadle) on Dec 14, 2021 at 21:02 UTC
|
Hi
May I suggest you delve into mod_perl?
Once you get the hang of it, you can do anything you want; I skipped the cgi-bin part altogether To install, it's easier to use the distribution packages (Debian in my case, so : apt install libapache2-request-perl libapache2-mod-perl2 libapache2-mod-apreq2
)
https://compta.libremen.com
Logiciel libre de comptabilité générale en partie double
| [reply] |
|
| [reply] |
|
True. I was fortunate to find it 15 years ago, when the mod_perl list was very active, hence got a lot of guidance, and there are a few gotchas. Now that I'm replying to you, I recall that I did have to study this book before I could be operational.
However I found the effort was worth it because you can do so much with mod_perl (I build web based applications for a living, the hooks to the Apache response phases are awesome); and you get to write perl code, not cgi code. Also, very efficient.
Anyhow, you are right, not for someone who is building a hobby site. But if one wants to make a serious one, it's a great tool.
https://compta.libremen.com
Logiciel libre de comptabilité générale en partie double
| [reply] |