LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-28-2005, 04:59 PM   #1
don_wombat
LQ Newbie
 
Registered: Nov 2004
Posts: 26

Rep: Reputation: 15
Apache's CGI directory


Hey all,

I'm having difficulty getting my apache to execute some cgi scripts.

First off, my CGI scripts live in /var/www/cgi-bin. I have a test script called hello.cgi which is as follows:

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

This should be enough to test the CGI functionality.

When I run this file under command line, I get the following:

> perl /var/www/cgi-bin/hello.cgi
Content-type: text/html

Hello, world!

This tells me that perl is accepting the script and it does work.

Ok, so looking at the httpd error file, I get this:

[Mon Feb 28 15:50:16 2005] [error] [client 66.231.96.142] (2)No such file or directory: exec of '/var/www/cgi-bin/hello.cgi' failed
[Mon Feb 28 15:50:16 2005] [error] [client 66.231.96.142] Premature end of script headers: hello.cgi

Here are the permissions on the file:

> ls -la /var/www/cgi-bin/hello.cgi
-rwxr-xr-x 1 apache apache 116 Feb 28 15:49 /var/www/cgi-bin/hello.cgi


I'm out of ideas.............
 
Old 02-28-2005, 07:56 PM   #2
NoStop
Member
 
Registered: Feb 2005
Location: Canada
Distribution: Debian Etch - Enlightenment E17
Posts: 116

Rep: Reputation: 15
With what did you write hello.cgi?

If you do a cat -v /var/www/cgi-bin/hello.cgi are there any extra characters displayed at the end of the line(s)?

Cheers
 
Old 02-28-2005, 09:19 PM   #3
don_wombat
LQ Newbie
 
Registered: Nov 2004
Posts: 26

Original Poster
Rep: Reputation: 15
dos lines.... could be.

Here is the output.....

> cat -v /var/www/cgi-bin/hello.cgi
#!/usr/bin/perl
# hello.pl --my first perl script!
print "Content-type: text/html\n\n"
pring "Hello, world!\n";
 
Old 02-28-2005, 09:47 PM   #4
don_wombat
LQ Newbie
 
Registered: Nov 2004
Posts: 26

Original Poster
Rep: Reputation: 15
FYI: The error still remains after I learned how to spell print!!!

No matter what configuration I try, this is what my httpd error log is showing:

[Mon Feb 28 20:37:37 2005] [error] [client 127.0.0.1] Premature end of script headers: hello.cgi

What boggles my mind is that when I run it cli, I get.....

[root@hyrule cgi-bin]# perl hello.cgi
Content-type: text/html

Hello, world!
[root@hyrule cgi-bin]#
 
Old 03-01-2005, 12:21 AM   #5
NoStop
Member
 
Registered: Feb 2005
Location: Canada
Distribution: Debian Etch - Enlightenment E17
Posts: 116

Rep: Reputation: 15
Will it run in a console without preceding it with "perl"? Just typing hello.cgi and seeing if it would run? I never bothered to ask whether it had the right permissions set to it. Did you do a chmod 755 to that script?

Cheers
 
Old 03-01-2005, 12:35 AM   #6
NoStop
Member
 
Registered: Feb 2005
Location: Canada
Distribution: Debian Etch - Enlightenment E17
Posts: 116

Rep: Reputation: 15
Oops, I should have said, trying running it by typing:

./hello.cgi

Cheers
 
Old 03-01-2005, 08:50 AM   #7
don_wombat
LQ Newbie
 
Registered: Nov 2004
Posts: 26

Original Poster
Rep: Reputation: 15
Hey,

Yeah, the execute bit is set. It's chmod is 755.

> ls -la hello.cgi
-rwxr-xr-x 1 apache apache 113 Feb 28 20:44 hello.cgi
> ./hello.cgi
Content-type: text/html

Hello, world!


One thing I forgot to mention is that I wrote this with vi, not a windows notepad/wordpad that adds all the carriage returns and such.
 
Old 03-01-2005, 01:14 PM   #8
NoStop
Member
 
Registered: Feb 2005
Location: Canada
Distribution: Debian Etch - Enlightenment E17
Posts: 116

Rep: Reputation: 15
On my system, a Mandrake 10.1 installation, a test.cgi script is automatically installed in the cgi-bin directory. Didn't notice if you mentioned what distro you're using or whether you have this script pre-installed?

If you do, what happens when you go to:

http://localhost/cgi-bin/test.cgi

Here that test.cgi is owned by root.

Cheers
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Cannot access cgi-bin directory for Nagios hywaydave23 Linux - Software 1 10-12-2005 07:16 AM
Apache: png file in CGI directory doza Linux - Software 2 08-27-2004 09:05 AM
cgi-perl directory init-5 General 4 09-16-2003 06:48 PM
Apache's Index XxAndyxX Linux - Software 2 03-16-2003 01:34 PM
Question on virtual hosts and CGI-BIN directory cgchris99 Linux - General 9 10-11-2002 12:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:48 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration