LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-14-2004, 09:44 AM   #1
Alan Powell
LQ Newbie
 
Registered: Nov 2003
Location: UK
Distribution: Redhat
Posts: 10

Rep: Reputation: 0
Unhappy Premature Script Failure


Hello all, can you help please? I am a newbie imho although on a steep learning curve I have checked various references and websources but still feel I could benefit from some advice.

I am ditching using a win2K server for all sorts of reasons and am migrating to Linux RH9. My server is built and seems to work ok when I have a default site to serve with Apache 2.0.40 for html and php. I fully updated the build with synaptic.

Following difficulty with Error 500 and premature script failure with a name based virtual host set up, I reverted to a standard single hostname set up and the NSA standard httpd.conf written by Rob McCool. I have set my group and ownership of directory and files to apache for /var/www/<all subs and content>. The permissions are set so that the directories are readable and executable by everybody (rwxr-xr-x) and the files are chmodded to 0755 (-rwxr-xr-x) in the /var/www/cgi-bin directory.

The log error purely mentions the premature failure of the scripts irrespectively whether they are .pl or .cgi

My questions are: -

Should my webserved directories and contents have group and ownership ideally set to apache?
My files need to have chmod 0755 <y/n>?
The error message indicates that the files are being accessed - the error is
filesystem access rather than httpd server based?

Is there a standard test setup that someone can share with me perhaps?

Thanks in advance.

Regards

Alan
 
Old 04-14-2004, 02:12 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Your scripts will need to be readable an accessable by the user apache. For more information about permissions see:
http://wiki.linuxquestions.org/wiki/Permissions

You could have permissions of 500 if the owner is apache.

To find out why you are getting these errors look for entries in your error_log file about the time that you accessed the cgi script. if you are unsure then post the message from the log file.
 
Old 04-15-2004, 04:57 AM   #3
Alan Powell
LQ Newbie
 
Registered: Nov 2003
Location: UK
Distribution: Redhat
Posts: 10

Original Poster
Rep: Reputation: 0
Question

Thanks for that David. I reviewed the reference and understand setting the permissions and the reasons why.

I have managed now to establish the following and would like further help.

I have checked that my httpd.conf is loading the cgi module.

For the following test script: -

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "<html><head>\n";
print "<title>hello world test</title></head>\n";
print "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#FF0000\" vlink=\"#800000\">\n";
print "<h1>hello world!</h1>\n";
print "</body></html>\n";

I get this exact message from the error log: -

[Thu Apr 15 10:28:28 2004] [error] [client 192.168.0.12] Premature end of script headers: helloworld.pl, referer: http://192.168.0.31/index.php

Here are my environment settings: -

BASH=/bin/bash
BASH_ENV=/root/.bashrc
BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release" [5]="i386-redhat-linux-gnu")
BASH_VERSION='2.05b.0(1)-release'
COLORS=/etc/DIR_COLORS.xterm
COLORTERM=gnome-terminal
COLUMNS=80
DIRSTACK=()
DISPLAY=:0.0
EUID=0
GDMSESSION=Default
GNOME_DESKTOP_SESSION_ID=Default
GROUPS=()
GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc-1.2-gnome2
G_BROKEN_FILENAMES=1
HISTFILE=/root/.bash_history
HISTFILESIZE=1000
HISTSIZE=1000
HOME=/root
HOSTNAME=development
HOSTTYPE=i386
IFS=$' \t\n'
INPUTRC=/etc/inputrc
LANG=en_GB.UTF-8
LESSOPEN='|/usr/bin/lesspipe.sh %s'
LINES=24
LOGNAME=root
LS_COLORS='no=00:----etc --- tif=00;35:'
MACHTYPE=i386-redhat-linux-gnu
MAIL=/var/spool/mail/root
MAILCHECK=60
OLDPWD=/var/www
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
PIPESTATUS=([0]="0")
PPID=2488
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
PS1='[\u@\h \W]\$ '
PS2='> '
PS4='+ '
PWD=/var/www/cgi-bin
QTDIR=/usr/lib/qt-3.1
SESSION_MANAGER=local/development:/tmp/.ICE-unix/1949
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=2
SSH_AGENT_PID=2007
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SSH_AUTH_SOCK=/tmp/ssh-XXqPl0Ev/agent.1949
SUPPORTED=en_GB.UTF-8:en_GB:en
TERM=xterm
UID=0
USER=root
USERNAME=root
WINDOWID=46137608
XAUTHORITY=/root/.Xauthority
XMODIFIERS=@im=none
_=
i=/etc/profile.d/which-2.sh


The error code does not change if I comment the #!/usr/bin/perl line out!!!

So this says to me that the script is found but not even opening. Here is the listing of the directory permissions and its contents: -

in /
drwxr-xr-x 22 root root 4096 Apr 15 10:43 var

in/var
drwxr-xr-x 19 root root 4096 Apr 15 10:40 www

in/var/www
drwxr-xr-x 2 root root 4096 Apr 15 10:39 cgi-bin

in /var/www/cgi-bin
-rwxr-xr-x 1 apache apache 385 Apr 14 14:00 helloworld.pl

I still cannot see what is wrong and am confused since I can run a simple perl file.pl test and get command line output irrespective of whether I state /usr/bin/perl file.pl or without the path.

Anything you can spot please?

Thanks in advance
 
Old 04-15-2004, 01:00 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
The first thing to check is that perl in that location:
whereis perl

If it is there then the only thing I think you need to add is an exit statement:
Code:
#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "<html><head>\n";
print "<title>hello world test</title></head>\n";
print "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#FF0000\" vlink=\"#800000\">\n";
print "<h1>hello world!</h1>\n";
print "</body></html>\n";
exit;
To help tidy the code up you may want to use:
Code:
#!/usr/bin/perl

print <<"EOF";
Content-type: text/html

<html>
 <head>
  <title>hello world test</title>
 </head>
 <body bgcolor="#FFFFFF" text="#000000" link="#FF0000" vlink="#800000">
  <h1>hello world!</h1>
 </body>
</html>
EOF

exit;
 
  


Reply



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 bhomass Debian 1 12-02-2005 05:31 PM
Premature firewall script metallica1973 Linux - Security 2 09-17-2005 01:21 PM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
Perl/CGI Problem "Premature Premature end of script headers: countdown.pl" newuser455 Linux - Software 2 07-18-2004 11:47 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:06 PM.

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