LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   perl problem? apache problem? cgi problem? (https://www.linuxquestions.org/questions/linux-software-2/perl-problem-apache-problem-cgi-problem-93960/)

WorldBuilder 09-17-2003 06:51 PM

perl problem? apache problem? cgi problem?
 
Hi all, this is actually kind of a continuation of a post I made at http://www.linuxquestions.org/questi...threadid=93823

I got a lot of great help there, and there is only one thing that is still not working. Here's the story.

I run apache 2.0.x on a RH 8 server. I THINK I got cgi-bin working properly (but would like some validation!). Now, in my cgi-bin directory, there are 3 files: "test-cgi" and "printenv" (both of which are there from the apache installation) as well as a cgi script I created for an introductory perl class called "hello.cgi".

I noticed some things...

First, here is the code for all 3 files right now:


test-cgi:
#!/bin/sh

# disable filename globbing
set -f

echo Content-type: text/plain
echo

echo CGI/1.0 test script report:
echo

echo argc is $#. argv is "$*".
echo

echo SERVER_SOFTWARE = $SERVER_SOFTWARE
echo SERVER_NAME = $SERVER_NAME
echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
echo SERVER_PROTOCOL = $SERVER_PROTOCOL
echo SERVER_PORT = $SERVER_PORT
echo REQUEST_METHOD = $REQUEST_METHOD
echo HTTP_ACCEPT = "$HTTP_ACCEPT"
echo PATH_INFO = "$PATH_INFO"
echo PATH_TRANSLATED = "$PATH_TRANSLATED"
echo SCRIPT_NAME = "$SCRIPT_NAME"
echo QUERY_STRING = "$QUERY_STRING"
echo REMOTE_HOST = $REMOTE_HOST
echo REMOTE_ADDR = $REMOTE_ADDR
echo REMOTE_USER = $REMOTE_USER
echo AUTH_TYPE = $AUTH_TYPE
echo CONTENT_TYPE = $CONTENT_TYPE
echo CONTENT_LENGTH = $CONTENT_LENGTH

hello.cgi:
#!/usr/bin/perl

use CGI ':standard';
use CGI::Carp 'fatalsToBrowser';

$message = "Hello World!";

print header,
start_html($message),
h1($message),
h2($message),
h3($message),
h4($message),
h5($message),
h6($message),
hr,
end_html;

printenv:
#!/usr/bin/perl
##
## printenv -- demo CGI program which just prints its environment
##

print "Content-type: text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}

From the get-go, "test-cgi" worked when I viewed it in a web browser, but "printenv" and hello.cgi did not. I finally got "printenv" to work. I did so by changing the path to the PERL interpreter. You'll notice that printenv and hello.cgi are PERL scripts, but test-cgi is not. Well, the path to my PERL interpreter is /usr/bin/perl. printenv USED to be /usr/local/bin/perl. As soon as I changed that, it started working. Now, the output in a browser for that is:

DOCUMENT_ROOT="/home/www"
GATEWAY_INTERFACE="CGI/1.1"
HTTP_ACCEPT="image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*"
HTTP_ACCEPT_ENCODING="gzip, deflate"
HTTP_ACCEPT_LANGUAGE="en-us"
HTTP_CONNECTION="Keep-Alive"
HTTP_HOST="www.bartlett-family.net"
HTTP_USER_AGENT="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin"
QUERY_STRING=""
REMOTE_ADDR="192.168.5.16"
REMOTE_PORT="1979"
REQUEST_METHOD="GET"
REQUEST_URI="/cgi-bin/printenv"
SCRIPT_FILENAME="/usr/local/apache2/cgi-bin/printenv"
SCRIPT_NAME="/cgi-bin/printenv"
SERVER_ADDR="24.128.150.74"
SERVER_ADMIN="postmaster@bartlett-family.net"
SERVER_NAME="www.bartlett-family.net"
SERVER_PORT="80"
SERVER_PROTOCOL="HTTP/1.1"
SERVER_SIGNATURE="<address>Apache/2.0.46 (Unix) PHP/4.3.2 Server at www.bartlett-family.net Port 80</address>\n"
SERVER_SOFTWARE="Apache/2.0.46 (Unix) PHP/4.3.2"

COOL! Ok, so I can now assume that cgi and perl are working, right? Yes, No, Maybe? But why is my hello.cgi script not working? Let me know if I am missing something! Thanks!

Chris

PS. The only other thing I can think of is this: While in the cgi-bin directory:

# ls -l
total 12
-rwxr-xr-x 1 chris chris 264 Sep 17 15:07 hello.cgi
-rwxr-xr-x 1 11056 303 268 Sep 17 16:09 printenv
-rwxr-xr-x 1 11056 303 757 Aug 24 1999 test-cgi

The only other thing that strikes me as odd is that the files other than hello.cgi are owned by whatever the hell the 303 and 11056 numbers are, while hello.cgi is owned by me... Does that matter for some reason?

trickykid 09-17-2003 07:45 PM

Lets not start the existing discussion in a new thread, this is against the rules. Lets continue in the existing one please.
I have reported this thread and it should be closed.

Regards.

http://www.linuxquestions.org/rules.php


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