Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am migrating our internal webserver over from UNIX to Linux.
we are using formmail.cgi for html forms.
I keep getting Premature end of script headers error in the logs and in your browser you get an internal server error when trying to submit a html form.
file ownership is 755, there are no typos in the referrers and the domain is also listed in the referrers.
Two possibilities in my experience:
1. the #! line is missing or pointed to the wrong place (is formmail.cgi the same as formmail.pl -- that is, is it a perl script?)
Code:
which perl
make the #! the same as the result of that
2. the file contains CRLF line ends (\r\n -- "DOS line ends") instead of l/unix LF (\n). This can happen if the script was uploaded (FTP/SFTP) from a Windows PC in binary mode instead of ascii mode [AFAIK, the ONLY thing ascii mode does is convert the line ends]
A quick way to check that is to open the script in vi/vim. If the line ends are CRLF, it will display ^M at the ends of the lines.
It's also possible that the web directory doesn't allow CGI, but I don't think that will give you the "Premature end of script headers" error. Be sure it has:
Never heard of FormMail before but I thought I would check it out. I downloaded the script and wrote a short form to call it. I get an additional error:
Code:
[Thu May 25 18:36:29.685511 2017] [cgi:error] [pid 844] [client 192.168.2.3:36172] AH01215: Can't use 'defined(%hash)' (Maybe you should just omit the defined()?) at /usr/lib/cgi-bin/FormMail.pl line 243.: /usr/lib/cgi-bin/FormMail.pl, referer: http://192.168.2.3/perl/formmail.html
[Thu May 25 18:36:29.686511 2017] [cgi:error] [pid 844] [client 192.168.2.3:36172] End of script output before headers: FormMail.pl, referer: http://192.168.2.3/perl/formmail.html
Omitting "defined" as the above recommends eliminated the errors.
perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
I'm using vi to edit the file so I don't have ^M at the end of the rows
this is what I have:
<Directory "/htdocs/thesource/corp/cgi-bin">
Options Indexes FollowSymLinks +ExecCGI +Includes
XBitHack full
AllowOverride None
Order allow,deny
Allow from all
I have the domain added in the referrer as well
Log file:
[Fri May 26 08:16:29 2017] [error] (2)No such file or directory: exec of '/cgi-bin/FormMail_original.cgi' failed
[Fri May 26 08:16:29 2017] [error] [client 10.226.40.1:54192] Premature end of script headers: FormMail_original.cgi, referer: http://XXX.stholdco.com/corp/tools/feedback.htm
premature end usually means you have a pair of delimiters (like <tag> </tag> or anything else) and the closing delimiter was not found. In your post #4 it can be </Directory>, but you did not post the whole script, so it is only a wild guess. From the other hand you posted a file not found ('/cgi-bin/FormMail_original.cgi'). I think that is not /cgi-bin, there should be something before that, probably an environment variable or other settings which is missing/not properly set.
[Fri May 26 08:16:29 2017] [error] (2)No such file or directory: exec of '/cgi-bin/FormMail_original.cgi' failed
[Fri May 26 08:16:29 2017] [error] [client 10.226.40.1:54192] Premature end of script headers: FormMail_original.cgi, referer: http://XXX.stholdco.com/corp/tools/feedback.htm
OK! That error is saying, pretty clearly, that the web server (Apache?) can't find the file specified in the <form action tag Please post that line from the web page.
A guess, based on the error:
Is /htdocs/thesource/corp/ the DocumentRoot for the domain? The error is indicating that either the /cgi-bin path is not directly under the DocumentRoot OR there is no script named FormMail_original.cgi in that directory. In your original post you said formmail.cgi
Matt Wright's FormMail script is very well written and very secure, if implemented properly. However every cracker in the world knows about it, and, since it's open source, can often find ways to break in and abuse it.
On the sites I maintain, I have added one more step to help prevent that abuse...I rename the script to something else.
Just thought I'd pass that on.
Amen. Do you get "404 Not Found" or "500 Internal Server Error"?
I'm guessing it's line endings as Sean stated in post #2 and "#!/usr/bin/perl^M" is failing.
My server outputs "AH02811: script not found or unable to stat:" if it can't find the file.
phipm1 posted the entries from the apache error log, which doesn't record the error codes. We'd need to see the corresponding entry from the access log, which would show the error code.
When I set up the situation of a not found script on my server, I get a 404 error in the access log, and
Code:
script not found or unable to stat:
in the error log. I do NOT get Premature end of script headers. Hmmm
I get exactly the same error as phipm1 when I munge the #! in the formmail script (!!)
Have you (phipm1) confirmed that the #! is pointing correctly to perl? It could be in a different place on your new OS than it was in your UNIX installation.
[error] (2)No such file or directory: exec of '/cgi-bin/FormMail.cgi' failed
[error] Premature end of script headers: FormMail.cgi, referer: http://xxx.domain.com/corp/tools/feedback.htm
the domain is in the referrer as well as the correct path to feedback.htm page
[error] (2)No such file or directory: exec of '/cgi-bin/FormMail.cgi' failed
[error] Premature end of script headers: FormMail.cgi, referer: http://xxx.domain.com/corp/tools/feedback.htm
the domain is in the referrer as well as the correct path to feedback.htm page
and
Code:
which perl
gives you the same thing as in the #! line?
If so, then I'm stumped. A mis-directed or munged #! line is the only thing I can replicate the error with.
Please also confirm the action in the form tag in feedback.htm matches the file name in cgi-bin ...you've posted two different spellings of the script. Still, a missing script doesn't give the exec failed and Premature end of script headers (on my apache server anyway)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.