Link to home
Start Free TrialLog in
Avatar of rajasree
rajasree

asked on

Internal Server Error

When I run this  simple cgi program, I get an Internal Server Error.

        #!/usr/bin/perl
        print "Content-type: text/html\r\n\r\n";
        print "Hello, World.";

Apache log files show the following error:

[Fri Aug 30 15:17:04 2002] [error] (8)Exec format error: exec of /var/www/cgi-bin/first.pl failed
[Fri Aug 30 15:17:04 2002] [error] [client 236.200.2.103] Premature end of script headers: /var/www/cgi-bin/first.pl  

Any idea what this means?
Thanks!
Avatar of Chris S
Chris S
Flag of India image

1) set permissions on first.pl to 755
2) is /usr/bin/perl the path to the perl ?
3) is perl installed ?
4) is it linux or windows ?
Avatar of rajasree
rajasree

ASKER

1. Permissions are set to 755
2. whereis perl shows /usr/bin/perl
3. I am able to run perl programs, the error happens only for cgi
4. I am using Redhat linux 7.3

In my apache httpd.conf, the path for cgi is given as /var/www/cgi-bin

Thanks for your time!
if you have telnet access
open a vi editor and key in a simple perl program and try to access it as cgi...

if it works then the error is due to the windows/unix ....escape sequence problem

chris
also try naming the scripts as .cgi instead of .pl
also see whether your VERY FIRST line is

#! /usr/bin/perl
and retry after uploading the script in ftp as ascii format
Thanks for your reply. But I did make sure that

1. there are no dos characters. I did type the 3 liner program(shown in my question) using vi.
The perl program runs perfectly at command line
2. I did try renaming to .cgi, no luck
3. very first line is #!/usr/bin/perl

I am thinking the problem might be due to my apache server configuration? Does it have to be explicitly set up to access cgi files?
This server is newly set up and never ran cgi programs before. I am able to run regular perl programs at command line on this server.
Thanks for your time!
Also, isnt it weird that the log files does not give more info as to what kind of error it is ?
Well, I've never seen a script print \r\n\r\n, but rather but \n\n

Could you try just:
print "Content-type: text/html\n\n";
instead?  

Sorry if I'm way off and that has nothing to do with it.
Did try after removing the \r characters, no luck still :(

[root cgi-bin]# more first.pl
        #!/usr/bin/perl
        print "Content-type:text/html\n\n";
        print "Hello, World.";
Rajasree,

Your apache config looks fine.

Could you test using CGI.pm instead.
---
#!c:/perl/bin/perl
use CGI;

my $q = new CGI;

print $q->header;
print $q->start_html;
print "Hello World\n";
print $q->end_html;
---

See if this works.

And make sure this falls into /var/www/cgi-bin/

The filename should not be a problem since anything in this folder would be treated as CGI program.  

Did you make any changes to other section in httpd.conf

If the problem persist, try restarting apache, and/or the machine.  I knew this might sound absurd, but sometime it works.

cheers.
Using the same 3 lines, I too see the internal error message. However, turning on warnings allows the page to be displayed - not sure why.

Try changing the first line to:

#!/usr/bin/perl -w

elminster/rajshree,

-w is to eliminate all warning.  (IHMO), I guess that explains why the error produced by Apache.  Somehow, I believe something is not "quite" right with that Perl.

Basically what might have happened  is that, when the scripts is executed by apache (with userid apache),  there might be additional error message generated.

To see what addition info is printed out; turn on error loggin for CGI program


ScriptLog filename

The filename would be relative to ServerRoot (using logs/cgi.log would cause all error produced by CGI to be logged to file cgi.log in logs directory).

More infio.
http://httpd.apache.org/docs/mod/mod_cgi.html
http://httpd.apache.org/docs/mod/mod_cgi.html#scriptlog

And, please do not use -w swith, otherwise all error/warning will be surpressed.

cheers.
Samri,
Your code using cgi.pm works!  Not sure what this means?

I created a file logs/cgi.log and added ScriptLog directive to my httpd.conf like this. (I added only the 3rd line)

ServerType StandAlone
ServerRoot /etc/httpd/
ScriptLog logs/cgi.log
                           
But got the following error. Sorry, Im new here :(

[root init.d]# ./httpd restart
Stopping httpd: [  OK  ]
Starting httpd: Syntax error on line 48 of /etc/httpd/conf/httpd.conf:
Invalid command 'ScriptLog', perhaps mis-spelled or defined by a module not incl
uded in the server configuration
[FAILED]  
ASKER CERTIFIED SOLUTION
Avatar of samri
samri
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
On a second machine, the same script worked fine.
Both were typed in using 'vim' on each machine.

Both ran when run using:

perl test.cgi

but the first machine fell over when just:

./test.cgi

was typed.

After looking at each byte in the files, the only difference was the cr/lf at the end of each line.

It seems that the first version of vim uses the DOS linefeed hex characters 0x0d AND 0x0a). The second version of vim uses just the hex 0x0a.

When the 0x0d byte was removed from the script on the first machine it works fine.

It seems that (at least in my case), the vi editor is set to use DOS line feeds. Using 'emacs' indeed showed the file to be in 'DOS' mode. Emacs, though writes the file 'correctly'.

If you want to use 'vi', try re-typing the file, but instead of pressing 'ENTER' press 'CTRL-J' instead. This is only affecting the shebang line, so  

#!/usr/bin/perl<CTRL_J>
print "Content-etc" <ENTER>

etc

HTH
Just re-read Chris18's message - I took the 'escape sequence' to mean the '\r\n', not the cr/lf issue. You later say you've 'No DOS characters' - I thought you were maybe referring to the '^M' some DOS editors leave behind.

Apologies if you've already checked all this.
(Same symptoms - different cause?)
      #!/usr/bin/perl
       print "Content-type:text/html\n\n";
       print "Hello, World.";

now the indendation above

I mean the space between []

[      ]#!/usr/bin/perl

if there is any space remove those spaces

chris
samri, you guessed it right!!!  Someone corrupted my httpd.conf file , deleted most of the entries, and I never knew!
just now copied over the conf file from a different machine, and restarted apache, and my code worked just fine!  Thanks for all your help.

btw, what is IMHO ?

Thanks also to  elminister and chris18 for your precious time!

samri , you got to tell me what made u think that i shd restart my apache.
Is this something i shd be doing as a routine?

Thanks again :)
Rajasree
Rajasree,

IMHO: In My Humble Opinion

Gee...  Just discovered this less than a week (before this I'm as puzzled as you are :)

More jargon:
http://www.stevegrossman.com/jargpge.htm

Or ran this search in Google.
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=chat+jargon

cheers.