Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I just start to learn CGI, I try to know some information about my server, my script looks like:
#! /usr/local/bin/perl print "Content-type: text/html", "\n\n"; print "<HTML>", "\n"; print "<HEAD><TITLE>About this Server</TITLE></HEAD>", "\n"; print "<BODY><H1>About this Server</H1>", "\n"; print "<HR><PRE>", "\n"; print "Server Name: ", $ENV{'SERVER_NAME'}, "<BR>","\n"; print "Running on Port: ", $ENV{'SERVER_PORT'}, "<BR>", "\n"; print "Server Software: ", $ENV{'SERVER_SOFTWARE'},"<BR>", "\n"; print "Server Protocol: ", $ENV{'SERVER_PROTOCOL'},"<BR>", "\n"; print "CGI Revision: ", $ENV{'GATEWAY_INTERFACE'},"<BR>", "\n"; print "<HR></PRE>", "\n"; print "</BODY></HTML>", "\n"; exit (0);
But the output has no any information about server:
Content-type: text/html <HTML> <HEAD><TITLE>About this Server</TITLE></HEAD> <BODY><H1>About this Server</H1> <HR><PRE> Server Name: <BR> Running on Port: <BR> Server Software: <BR> Server Protocol: <BR> CGI Revision: <BR> <HR></PRE> </BODY></HTML>
I use Red Hat 7.2 version OS, and SSH both give me the same result, What is wrong? Thanks in advance!

Replies are listed 'Best First'.
Re: About server information
by projekt21 (Friar) on Jul 29, 2003 at 13:52 UTC

    Are you running this on a command line? Then your output is right, as none of those environment variables are set.

    chmod +x your file, place it in your cgi-bin directory and call it via a browser.

    and always "use CGI" ...

    use CGI; my $q = CGI->new; print $q->header; print "<HTML>", "\n"; # .....

    alex pleiner <alex@zeitform.de>
    zeitform Internet Dienste

      Thank you so much! I am really shame about knowing nothing about CGI yet. Do I have to use commond: mkdir cgi-bin to make a cgi-bin directory? and how to make a call by browser? Great thanks again!

        Well, that's tough :-). No need to shame, we all started once.

        If that's your Redhat System, you may find the webserver Apache installed somewhere (maybe in /usr/local/apache, maybe elsewhere). CGI provides an interface for that webserver to run a script and output its result. Apache is configured via a file named httpd.conf. Within this file a directory needs to be configured as (example):

        <Directory "/usr/local/apache/cgi-bin"> AllowOverride AuthConfig Order allow,deny Allow from all Options +ExecCGI ### this is the relevant piece </Directory> ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"

        So you place your script in that cgi-bin directory and open a web browser with the URL:

        http://localhost/cgi-bin/your-script.pl

        The output will show your server stats.

        If that's not your own system, please ask the question "Where can I place my CGI scripts?" to your webmaster. She will help you.

        Perhaps someone redhat compatible can give some better directions to start.

        alex pleiner <alex@zeitform.de>
        zeitform Internet Dienste

Re: About server information
by DrHyde (Prior) on Jul 29, 2003 at 13:54 UTC
    Which HTTP server (exact version, plus what extra modules if any?). Is there any other software involved - for instance, does your service provider wrap your CGIs in cotton wool in an attempt to protect against programmer error?