cgi not working Premature end of script headers

N

NoAgendas

Guest
Getting Premature end of script headers on all cgi files

They are 755 chmodded

I did not use ftp, I used scp to transfer them from one server to another.

I'm assuming this might be why they are not working, but I do not know

The apache logs only shows "Premature end of script headers"

How do I correct this?
 

PWSowner

Well-Known Member
Nov 10, 2001
2,901
4
343
ON, Canada
Interesting question. Maybe binary/ascii doesn't apply with scp.

The script did work on the other server, right?


Add this
use CGI::Carp qw(fatalsToBrowser);
near the top of the script and see if it helps.
 
N

NoAgendas

Guest
I downloaded the files locally, re-uploaded via ftp in ascii mode. I still get Internal Server Error message.

[Mon Aug 14 22:04:19 2006] [error] [client xx.xxx.19.185] Premature end of script headers: /home/user/public_html/cgi-bin/search.cgi
[Mon Aug 14 22:04:19 2006] [error] [client xx.xxx.19.185] File does not exist: /home/user/public_html/500.shtml
 
N

NoAgendas

Guest
suexec log:

[2006-08-15 13:12:22]: info: (target/actual) uid: (gotorg/gotorg) gid: (gotorg/gotorg) cmd: fpexe
[2006-08-15 13:19:30]: info: (target/actual) uid: (seekorg/seekorg) gid: (seekorg/seekorg) cmd: search.cgi
[2006-08-15 13:19:46]: info: (target/actual) uid: (seekorg/seekorg) gid: (seekorg/seekorg) cmd: search.cgi
[2006-08-15 13:20:43]: info: (target/actual) uid: (gotorg/gotorg) gid: (gotorg/gotorg) cmd: fpexe
[2006-08-15 13:20:44]: info: (target/actual) uid: (gotorg/gotorg) gid: (gotorg/gotorg) cmd: fpexe
[2006-08-15 13:20:45]: info: (target/actual) uid: (gotorg/gotorg) gid: (gotorg/gotorg) cmd: fpexe
[2006-08-15 13:23:12]: info: (target/actual) uid: (gotorg/gotorg) gid: (gotorg/gotorg) cmd: fpexe
[2006-08-15 13:23:12]: info: (target/actual) uid: (gotorg/gotorg) gid: (gotorg/gotorg) cmd: fpexe
[2006-08-15 13:23:47]: info: (target/actual) uid: (gotorg/gotorg) gid: (gotorg/gotorg) cmd: fpexe
[2006-08-15 13:37:09]: info: (target/actual) uid: (seekorg/seekorg) gid: (seekorg/seekorg) cmd: search.cgi

I tried chmodding the cgi files to 711, 755 and 777 - none worked
 
Last edited by a moderator:

webignition

Well-Known Member
Jan 22, 2005
1,876
2
166
I assume you've checked the basics?

- File owership correct?
- File permissions correct (no XXX7)
- Parent directory permissons correct (no XXX7)
- Definitely uploaded in ASCII mode?

Try running an affected script through the command line tool dos2unix. This will convert Windows-style line returns to Unix style (\r\n to \n if I remember correctly). Extraneous carriage returns can sometimes annoy things.
 
N

NoAgendas

Guest
Code:
[email protected] [/home/seekorg/public_html/cgi-bin]# ls -lh
total 226M
drwxr-xr-x   2 seekorg seekorg 4.0K Aug 14 23:32 ./
drwxr-x---  10 seekorg nobody  4.0K Aug 14 23:18 ../
-rw-r--r--   1 seekorg seekorg  18K Aug 14 21:45 cgiecho
-rw-r--r--   1 seekorg seekorg  18K Aug 14 21:45 cgiemail
-rwxrwxrwx   1 seekorg seekorg 2.9K Aug 14 21:45 entropybanner.cgi*
-rwxrwxrwx   1 seekorg seekorg 2.9K Aug 14 21:45 randhtml.cgi*
-rwxr-xr-x   1 seekorg seekorg 132K Aug 14 21:59 search.cgi*
-rwxrwxrwx   1 seekorg seekorg 7.8K Aug 14 21:45 search_template.html*
-rwxrwxrwx   1 seekorg seekorg  25K Aug 14 21:45 searchwords.log*
-rwxrwxrwx   1 seekorg seekorg 3.3K Aug 14 21:59 settings.zdat*
-rwxrwxrwx   1 seekorg seekorg 483K Aug 14 22:53 zoom_datetime.zdat*
-rwxrwxrwx   1 seekorg seekorg 1.1M Aug 14 22:52 zoom_descriptions.zdat*
-rwxrwxrwx   1 seekorg seekorg 7.1M Aug 14 22:01 zoom_dictionary.zdat*
-rwxrwxrwx   1 seekorg seekorg 1.2M Aug 14 22:53 zoom_pages.zdat*
-rwxrwxrwx   1 seekorg seekorg 107M Aug 14 23:59 zoom_pagetext.zdat*
-rwxrwxrwx   1 seekorg seekorg 989K Aug 14 22:53 zoom_titles.zdat*
-rwxrwxrwx   1 seekorg seekorg 108M Aug 14 22:35 zoom_wordmap.zdat*
[email protected] [/home/seekorg/public_html/cgi-bin]# dos2unix search.cgi
dos2unix: converting file search.cgi to UNIX format ...
[email protected] [/home/seekorg/public_html/cgi-bin]# dos2unix entropybanner.cgi
dos2unix: converting file entropybanner.cgi to UNIX format ...
[email protected] [/home/seekorg/public_html/cgi-bin]# dos2unix randhtml.cgi
dos2unix: converting file randhtml.cgi to UNIX format ...
Permissions correct on the above

cgi-bin chmod to 755 as well

Uploaded in ASCII using FileZilla, 100% positive on that.

Code:
[email protected] [/home/seekorg/public_html/cgi-bin]# dos2unix *
dos2unix: converting file cgiecho to UNIX format ...
dos2unix: converting file cgiemail to UNIX format ...
dos2unix: converting file entropybanner.cgi to UNIX format ...
dos2unix: converting file randhtml.cgi to UNIX format ...
dos2unix: converting file search.cgi to UNIX format ...
dos2unix: converting file search_template.html to UNIX format ...
dos2unix: converting file searchwords.log to UNIX format ...
dos2unix: converting file settings.zdat to UNIX format ...
dos2unix: converting file zoom_datetime.zdat to UNIX format ...
dos2unix: converting file zoom_descriptions.zdat to UNIX format ...
dos2unix: converting file zoom_dictionary.zdat to UNIX format ...
dos2unix: converting file zoom_pages.zdat to UNIX format ...
dos2unix: converting file zoom_pagetext.zdat to UNIX format ...
dos2unix: converting file zoom_titles.zdat to UNIX format ...
dos2unix: converting file zoom_wordmap.zdat to UNIX format ...
[email protected] [/home/seekorg/public_html/cgi-bin]# tail -f /usr/local/apache/logs/error_log
[Tue Aug 15 14:10:23 2006] [error] [client xxx.xxx.19.185] Premature end of script headers: /home/seekorg/public_html/cgi-bin/search.cgi
[Tue Aug 15 14:10:23 2006] [error] [client xxx.xxx.19.185] File does not exist: /home/seekorg/public_html/500.shtml
suexec logs:

[2006-08-15 14:10:23]: info: (target/actual) uid: (seekorg/seekorg) gid: (seekorg/seekorg) cmd: search.cgi
[2006-08-15 14:10:23]: error: target uid/gid (32011/32013) mismatch with directory (32011/32013) or program (0/0) or trusted user (0/10)
 
N

NoAgendas

Guest
That was the last I tried. What is the proper permission?

I tried the 3 711, 755, 777 and none worked.

I even disabled suexec, also did not work
 

DigitalN

Well-Known Member
Sep 23, 2004
419
1
168
Running the script from command line, will usally tell you what's wrong, if there is something wrong with the script itself, causing the error.


# perl -w script.cgi
 

BPrintz

Registered
Oct 28, 2004
4
0
151
Did you ever solve this problem, I have the same thing now... the scripts are valid and will run from shell, they use to be running from the cgi-bin however no longer seem to work.... very stange. Any insight?
 

2mhost.com

Active Member
Sep 4, 2001
36
0
306
if script run from shell and not in browser then remember to specify the output type that suit browsers

try this:

#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "hello world";