LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-02-2008, 10:29 PM   #1
klauswunderlich
LQ Newbie
 
Registered: Jan 2008
Distribution: openSuse, Debian, Ubuntu
Posts: 22

Rep: Reputation: 15
Apache 2 error: "Premature end of script headers"


I'm new to apache and webserving, and I'm trying to write a web interface for some scientific hardware using a cgi script. The script netcats the hardware control protocol over the network to the hardware elsewhere in the building.

I have a test script:

echo "Mary had a little lamb" | netcat 127.0.0.1 1234

Permissions are 755, and it executes fine from the shell. In the apache error log, I have:

[client 127.0.0.1] Premature end of script headers: testscript.cgi, referer: http://localhost/

Reading the apache manual troubleshooting guide for this error, I get to this bit:

"Even if the CGI runs fine from the command line, remember that the environment and permissions may be different when running under the web server. The CGI can only access resources allowed for the User and Group specified in your Apache configuration. In addition, the environment will not be the same as the one provided on the command line, but it can be adjusted using the directives provided by mod_env."


Ok, fine, I don't have *something* configured right. The trouble is, I don't know what that something could be. Does anyone have any ideas?
 
Old 04-03-2008, 03:00 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
You should modify it like this:
Code:
#!/bin/sh

echo "Content-type: text/plain"
echo
echo "Mary had a little lamb" | netcat 127.0.0.1 1234
 
Old 04-03-2008, 03:45 AM   #3
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
you can avoid some trouble with cgi using perl and the perl CGI module. But if you are not familiar with perl this will not help you much. Anyway there is a detailed documentation for the cgi setup in apache manual that usually resides in http://localhost/manual
The error log will be very useful for debugging, too. Its location is depending on your distro and the way you installed apache. If you installed as deb-package or rpm the conf file is in /etc/apache2 or /etc/httpd ...
 
Old 04-03-2008, 07:30 PM   #4
klauswunderlich
LQ Newbie
 
Registered: Jan 2008
Distribution: openSuse, Debian, Ubuntu
Posts: 22

Original Poster
Rep: Reputation: 15
Thanks, that fix worked perfectly. I didn't know I had to echo a header, now I've gone and read up on that. Merci!
 
Old 04-04-2008, 01:43 AM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
I didn't know I had to echo a header,
Not only, you have to echo and a blank line too.
Glad to see it worked.

Regards
 
  


Reply

Tags
apache



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Premature end of script Headers error in openwebmail silverstag Linux - Server 4 07-04-2012 04:35 AM
apache and cgi problem. Premature end of script headers. JAdj Linux - Software 1 10-25-2006 03:45 AM
Perl/CGI Problem "Premature Premature end of script headers: countdown.pl" newuser455 Linux - Software 2 07-18-2004 11:47 AM
Premature End of Script Headers (Error 500) bsdb3 Red Hat 5 05-06-2004 11:55 AM
"Premature end of script headers" bugging me ulto Programming 1 04-15-2004 06:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration