Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newbie help with CGI script...Running apache on FreeBSD

140 views
Skip to first unread message

rende

unread,
Dec 11, 2002, 2:40:05 PM12/11/02
to
Hi, I am very new to HTML in general and extremelty new to CGI (read
an introduction to it yesterday)...Currently I have an Apache server
running and an now experimenting with writing CGI scripts. However,
when following the directions in the Apache Documentation regarding
CGI scripts I am having a problem. I wrote the first.pl script it
describes, placed it in the proper directory and modified the file
permissions so I no longer got the forbidden message when trying to
request the script. Now however I get the following 2 error messages
from httpd-errors.log:

[error](2) No such file or directory: exec of file
/usr/local/www/cgi-bin/first.pl failed
[error] [client 192.168.0.2] Premature end of script headers:
/usr/local/www/cgi-bin/first.pl


However, when I do:

/usr/bin/perl /usr/local/www/cgi-bin/first.pl

from the command line, the script runs fine.


The script first.pl looks like this:

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


I checked the rest of the Apache documentation and can find nothing
that I have configured wrong. scriptalias is setup correctly in
httpd.conf, and /usr/bin/perl is the correct path to the interpreter.

Please let me know what could be going wrong here.

Thank you,
Doug.

--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html

Sharon Grant

unread,
Dec 11, 2002, 4:49:47 PM12/11/02
to
On Wed, 11 Dec 2002 19:40:05 GMT, in comp.infosystems.www.authoring.cgi, bubble...@hotmail.com (rende)
wrote:

>[error](2) No such file or directory: exec of file
>/usr/local/www/cgi-bin/first.pl failed
>[error] [client 192.168.0.2] Premature end of script headers:
>/usr/local/www/cgi-bin/first.pl
>
>
>However, when I do:
>
>/usr/bin/perl /usr/local/www/cgi-bin/first.pl
>
>from the command line, the script runs fine.
>
>
>The script first.pl looks like this:
>
>#!/usr/bin/perl
>print "Content Type: text/html\n\r\n\r";
>print "Hello, World!";

If you used a Windows text editing program to create the
script, it may contain carriage return (<CR>) characters
at the end of each line

If this is the case, the 'No such file or directory' error
is caused by the <CR> at the end of the first line:

#!/usr/bin/perl<CR>

If you are using a Windows text editor, you can usually
solve this problem by ensuring that your ftp program
uploads the file using ASCII mode (not BINARY). ASCII mode
FTP transfers will remove the <CR> character from the end
of each line

Alternatively, get a text editor which saves text files in
Unix format. Programmers File Editor is free:
http://www.lancs.ac.uk/people/cpaap/pfe/
--
Sharon

Alan J. Flavell

unread,
Dec 11, 2002, 5:16:28 PM12/11/02
to
On Dec 11, rende inscribed on the eternal scroll:

> when following the directions in the Apache Documentation regarding
> CGI scripts I am having a problem. I wrote the first.pl script it
> describes,

You seem to be working from
http://httpd.apache.org/docs/howto/cgi.html
(it's always nicer if you can be explicit)

> placed it in the proper directory and modified the file
> permissions so I no longer got the forbidden message when trying to
> request the script.

> Now however I get the following 2 error messages
> from httpd-errors.log:
>
> [error](2) No such file or directory: exec of file

^^^^^^^^^^^^^^^^^^^^^^^^^ something wrong here

> /usr/local/www/cgi-bin/first.pl failed
> [error] [client 192.168.0.2] Premature end of script headers:

-> that's probably a knock-on effect. Look for the first problem
first.

> However, when I do:
>
> /usr/bin/perl /usr/local/www/cgi-bin/first.pl
>
> from the command line, the script runs fine.

This isn't the real test, though. You should be able to demonstrate
that you can execute the script by hand directly as

/usr/local/www/cgi-bin/first.pl

without prefixing it with the name of the perl interpreter.

> The script first.pl looks like this:
>
> #!/usr/bin/perl
> print "Content Type: text/html\n\r\n\r";

er, no, it doesn't. Look at the original again. But that isn't the
specific problem.

> I checked the rest of the Apache documentation and can find nothing
> that I have configured wrong. scriptalias is setup correctly in
> httpd.conf, and /usr/bin/perl is the correct path to the interpreter.
>
> Please let me know what could be going wrong here.

If you're mixing Windows and unix, it seems possible that you have a
stray carriage-return on the shebang line. Try putting the -w option
on it, like

#!/usr/bin/perl -w

and try the various tests again.

If that does the trick, somebody else can explain what's behind it.

bashbrothers

unread,
Dec 20, 2002, 2:30:28 AM12/20/02
to
hey man, rename it to a .cgi
:)

"rende" <bubble...@hotmail.com> wrote in message
news:45372029.02121...@posting.google.com...

bashbrothers

unread,
Dec 20, 2002, 3:18:34 AM12/20/02
to
hey man, rename it to a .cgi
:)

"rende" <bubble...@hotmail.com> wrote in message
news:45372029.02121...@posting.google.com...

0 new messages