LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 09-17-2003, 11:56 AM   #1
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Rep: Reputation: 30
Apache server and cgi-bin?


I run an apache server on an RH 8 machine. How do I set the server up to use cgi-bin? I am very new to apache and the docs are a bit confusing. Any help? Thanks a million!

Chris
 
Old 09-17-2003, 12:00 PM   #2
WiZaC
Member
 
Registered: Sep 2003
Location: Denmark
Distribution: FreeBSD
Posts: 110

Rep: Reputation: 15
Do you have all installed, apache, and so on? chech httpd.conf, maybe are there something you have to edit =)
 
Old 09-17-2003, 12:09 PM   #3
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
For versions 1.3.x -> http://httpd.apache.org/docs/howto/cgi.html

For versions 2.0.x -> http://httpd.apache.org/docs-2.0/howto/cgi.html

Good stuff in the docs.. I don't mean to really point you to RTFM but why repeat ourselves here when the information is already available.
 
Old 09-17-2003, 12:16 PM   #4
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
I can sort of understand your point TrickyKid, but as I mentioned, the docs are a bit confusing. I am intelligent, but am new at this and it is confusing to me.

To answer your question, I think it's important to repeat yourselves in order to help someone who needs helping, period. That's what the site is here for. Not all of us are moderators who spend hours upon hours every day surfing this site, and the search function (although outstanding, as I have used it before) can often return more results than desired about slightly different problems. This can just confuse someone further. In instances such as my original post, I thought that this would be the easiest way for me to learn something with help from this great community. I will once again turn to the documentation for Apache.

Chris

PS. I am not attacking or criticizing you, Trick, just offering an answer to your question. You guys do outstanding work here, and have helped me countless times, for which I am grateful!
 
Old 09-17-2003, 12:35 PM   #5
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
Well, you still haven't given us any information to go on or maybe tell you a quick way. Is apache installed, did you install manually or is this the version your using during the Redhat default install? What version are you using? What have you tried so far?

In alot of cases, the default installation comes with cgi-bin enabled already. What does your httpd.conf file look like?

Regards.
 
Old 09-17-2003, 01:46 PM   #6
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
Quote:
I run an apache server on an RH 8 machine.
Apache is installed. I installed it manually from source code. It also works with php and MySQL. httpd.conf file is huge (of course). Would you like me to post the entire thing? Let me know. Thanks!

Chris

PS. It's Apache 2.0.x
 
Old 09-17-2003, 02:07 PM   #7
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
Ok, I seem to be getting somewhere... I am beginning to thing that cgi is already enabled. Not sure. The cgi-bin directory is located in: /usr/local/apache2. The httpd.conf file says this about ScriptAlias:

# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"

In the cgi-bin directory, there are 2 files, "test-cgi" and "printenv". I tried going to them through a browser and got errors. Then, I made them executable with "chmod 777 test-cgi" and "chmod 777 printenv". Now, when I go to the test-cgi file on the web, I get this:

CGI/1.0 test script report:

argc is 0. argv is .

SERVER_SOFTWARE = Apache/2.0.46 (Unix) PHP/4.3.2
SERVER_NAME = www.bartlett-family.net
GATEWAY_INTERFACE = CGI/1.1
SERVER_PROTOCOL = HTTP/1.1
SERVER_PORT = 80
REQUEST_METHOD = GET
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, */*
PATH_INFO =
PATH_TRANSLATED =
SCRIPT_NAME = /cgi-bin/test-cgi
QUERY_STRING =
REMOTE_HOST =
REMOTE_ADDR = 192.168.5.16
REMOTE_USER =
AUTH_TYPE =
CONTENT_TYPE =
CONTENT_LENGTH =

When I try to go to the printenv file, I get an error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, postmaster@bartlett-family.net and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


--------------------------------------------------------------------------------

Apache/2.0.46 (Unix) PHP/4.3.2 Server at www.bartlett-family.net Port 80

Also, I am taking an introductory PERL class at the college I attend and I have an account there. For our first assignment, we had to make a cheesy "Hello World" cgi script. I was told how to create the file and where to upload it to. It works. As a further test, I copied the file to my own cgi-bin directory and am trying to run it. That is giving me the exact same error as when I try to run printenv. I know I have PERL installed properly, but I have no idea if it needs to have some kind of "integration" with Apache. Here's the hello.cgi script:

#!/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;


Can you tell me why that's not working? I'd really like to figure this. I'll continue readimg, but can you guys offer further assistance? I'd appreciate it!

Chris

Last edited by WorldBuilder; 09-17-2003 at 02:09 PM.
 
Old 09-17-2003, 02:16 PM   #8
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
Here's a little more of my httpd.conf file if it helps!

# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/home/www">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI Multiviews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>

#
# Disable autoindex for the root directory, and present a
# default Welcome page if no other index page is present.
#
<LocationMatch "^/$>
Options -Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>

#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid. This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
# See also: http://httpd.apache.org/docs/misc/FAQ.html#forbidden
#
<IfModule mod_userdir.c>
#
# UserDir is disabled by default since it can confirm the presence
# of a username on the system (depending on home directory
# permissions).
#
UserDir disable

#
# To enable requests to /~user/ to serve the user's public_html
# directory, remove the "UserDir disable" line above, and uncomment
# the following line instead:
#
#UserDir public_html

</IfModule>

#
# Control access to UserDir directories. The following is an example
# for a site where these directories are restricted to read-only.
#
#<Directory /home/*/public_html>
# AllowOverride FileInfo AuthConfig Limit
# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
# <Limit GET POST OPTIONS>
# Order allow,deny
# Allow from all
# </Limit>
# <LimitExcept GET POST OPTIONS>
# Order deny,allow
# Deny from all
# </LimitExcept>
#</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents. The MultiViews Option can be used for the
# same purpose, but it is much slower.
#
DirectoryIndex index.html index.html.var

#
# AccessFileName: The name of the file to look for in each directory
# for access control information. See also the AllowOverride directive.
#
AccessFileName .htaccess

Hope that helps!

Chris

PS. My DocumentRoot is /home/www

Last edited by WorldBuilder; 09-17-2003 at 02:29 PM.
 
Old 09-17-2003, 02:30 PM   #9
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
Even more useful httpd.conf info for you...

# Aliases: Add here as many aliases as you need (with no limit). The format is
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL. So "/icons" isn't aliased in this
# example, only "/icons/". If the fakename is slash-terminated, then the
# realname must also be slash terminated, and if the fakename omits the
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings. If you
# do not use FancyIndexing, you may comment this out.
#
Alias /icons/ "/usr/local/apache2/icons/"

<Directory "/usr/local/apache2/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

#
# This should be changed to the ServerRoot/manual/. The alias provides
# the manual, even if you choose to move your DocumentRoot. You may comment
# this out if you do not care for the documentation.
#
Alias /manual "/usr/local/apache2/manual"

<Directory "/usr/local/apache2/manual">
Options Indexes FollowSymLinks MultiViews IncludesNoExec
AddOutputFilter Includes html
AllowOverride None
Order allow,deny
Allow from all
</Directory>

#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"

<IfModule mod_cgid.c>
#
# Additional to mod_cgid.c settings, mod_cgid has Scriptsock <path>
# for setting UNIX socket for communicating with cgid.
#
#Scriptsock logs/cgisock
</IfModule>

#
# "/usr/local/apache2/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/usr/local/apache2/cgi-bin">


Chris
 
Old 09-17-2003, 02:43 PM   #10
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
What you got on your test-cgi after making it executable means that CGI should be working, its most likely a problem with your scripts. Do the others have the correct permissions and or set to executable? chmod +x <filename> is the easiest way to make them executable. Its usually not good to make them chmod 777 but rather chmod 755 instead.
 
Old 09-17-2003, 02:48 PM   #11
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
As of right now, those 3 files (test-cgi, printenv, hello.cgi) are the only ones in the /usr/local/apache2/cgi-bin directory and they are all executable (I'll change them to 755 as you suggest). That's why I am confused as to what's going on. Any other thoughts?

Chris
 
Old 09-17-2003, 02:54 PM   #12
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
And you don't have anything else in your httpd.conf file that pertains to CGI ?

So apparently the test-cgi script works but the others don't?
 
Old 09-17-2003, 02:57 PM   #13
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
Quote:
And you don't have anything else in your httpd.conf file that pertains to CGI ?
Nothing else I can see, but would you like me to post the ENTIRE httpd.conf file? I'd be happy to, but it's huge, of course.

Quote:
So apparently the test-cgi script works but the others don't?
It would SEEM so, yes. Of course, I don't even know what "printenv" is supposed to do! I know what hello.cgi should do, but neither works.

Chris

PS. On a side note, apache starts when the computer is booted through the file /usr/local/apache2/bin/apachectl. When I play with apache, I stop and start it with /usr/local/apache2/bin/httpd. What is the difference between these two, apachectl and httpd?

Last edited by WorldBuilder; 09-17-2003 at 02:58 PM.
 
Old 09-17-2003, 03:14 PM   #14
WorldBuilder
Member
 
Registered: Mar 2003
Location: Massachusetts, USA
Distribution: RH 8, Solaris, Windoze eXPunged
Posts: 520

Original Poster
Rep: Reputation: 30
OK! I got printenv to work. 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";
}

NOW, I 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 me PERL interpreter is /usr/bin/perl. printenv USED to be /usr/local/bin/perl. As soon as I changed that, it works! 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 is working, right? But why is my hello.cgi script not working? Can you tell me that? 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?

Last edited by WorldBuilder; 09-17-2003 at 03:18 PM.
 
Old 09-17-2003, 07:48 PM   #15
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
Well, I'm still learning perl myself but it would most likely be a script problem, not perl, not apache or cgi problem. Apache is running, you can execute other scripts from your cgi-bin including a perl script that works.

That's all I can tell though, have you tried just making a more simple helloworld script to test as well?
 
  


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
Redhat 9 / Apache / cgi-bin ???? jeff0628 Linux - General 16 10-18-2003 06:50 AM
Apache cgi-bin in Mandrake 9.1 Edgemaster Linux - Newbie 1 08-14-2003 01:15 PM
.htaccess and cgi-bin (apache of course) finegan Linux - Software 4 05-01-2003 04:21 PM
no access to cgi-bin within Apache Mackeral Linux - Software 6 05-14-2002 05:15 AM
apache cgi-bin roadie Linux - General 6 06-16-2001 07:15 PM


All times are GMT -5. The time now is 07:18 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration