Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Configure CGI for apache 2.2.2 1

Status
Not open for further replies.

vortmax

Technical User
Aug 1, 2006
46
US
I'm attempting to configure Apache 2.2.2 to allow CGI. The server is a custom install on Fedora 5.

I have the server configured and running fine. My problem is configuring CGI to work. I changed the two lines in the httpd.conf in the script alias section file to point to my CGI-BIN direrctory. Doing this causes a 'FORBIDDEN' error.

So I went into the httpd.conf file and commented out the alias line (ScriptAlias /cgi-bin/ ), eliminating the protection of the cgi-bin directory. When i did this and tried to access a test script in the cgi-bin directory, instead of running the script, it just displays the code and does not parse it. Executing the script through the command line with the perl command runs the script without a problem.

So my initial thought was that the server was not running cgi, so I added a 'LoadModule mod_cgi blah/blah/blah' directly below the DSO section of the httpd.conf file (the cgi modules do exist in the modules directory.

Upon restarting Apache, I get an error saying that the cgi module is already loaded by default and it kills the service start.

so apparently cgi is running, it just won't parse code. any suggestions where to start?

Here is a copy of my httpd.conf file for reference:

#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL: for detailed information.
# In particular, see
# <URL:# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "/usr/local/etc/httpd" will be interpreted by the
# server as "/usr/local/etc/httpd/logs/foo.log".

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to point the LockFile directive
# at a local disk. If you wish to share the same ServerRoot for multiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "/usr/local/etc/httpd"

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#


<IfModule !mpm_netware_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User T28
Group T28
</IfModule>

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition. These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
ServerAdmin **********************

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName meso.ias.sdsmt.edu

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/ #
# 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
# # 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>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html index.htm
</IfModule>

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog logs/error_log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

<IfModule log_config_module>
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>

#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here. Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
#
CustomLog logs/access_log common

#
# If you prefer a logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
#CustomLog logs/access_log combined
</IfModule>

<IfModule alias_module>
#
# Redirect: Allows you to tell clients about documents that used to
# exist in your server's namespace, but do not anymore. The client
# will make a new request for the document at its new location.
# Example:
# Redirect permanent /foo
#
# Alias: Maps web paths into filesystem paths and is used to
# access content that does not live under the DocumentRoot.
# Example:
# Alias /webpath /full/filesystem/path
#
# If you include a trailing / on /webpath then the server will
# require it to be present in the URL. You will also likely
# need to provide a <Directory> section to allow access to
# the filesystem path.

#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the target 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/ "/home/T28/
</IfModule>

<IfModule cgid_module>
#
# ScriptSock: On threaded servers, designate the path to the UNIX
# socket used to communicate with the CGI daemon of mod_cgid.
#
#Scriptsock logs/cgisock
</IfModule>

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

<Directory "~/ AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
AddHandler cgi-script .cgi .pl
</Directory>


#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value. If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain

<IfModule mime_module>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig /
#
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi

# For type maps (negotiated resources):
#AddHandler type-map var

#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
</IfModule>

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type. The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
#MIMEMagicFile /
#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 #

#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall is used to deliver
# files. This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
#
#EnableMMAP off
#EnableSendfile off

# Supplemental configuration
#
# The configuration files in the / directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.

# Server-pool management (MPM specific)
#Include /
# Multi-language error messages
#Include /
# Fancy directory listings
#Include /
# Language settings
#Include /
# User home directories
#Include /
# Real-time info on requests and configuration
#Include /
# Virtual hosts
#Include /
# Local access to the Apache HTTP Server Manual
#Include /
# Distributed authoring and versioning (WebDAV)
#Include /
# Various default settings
#Include /
# Secure (SSL/TLS) connections
#Include /#
# Note: The following must must be present to support
# starting without SSL on platforms with no /dev/random equivalent
# but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
 
It sounds like you're set up correctly - Permission denied usually means exaclty that. Make sure user T28 has permission to execute the script.
 
that was the first thing I checked.

Everything from the document root down is owned by T28:T28 with RX permissions. T28 is the same user/group that apache runs as. I've double and triple checked this numerous times.

I continued to mess with it and did manage to get rid of the 'Permission denied' error. Now when loading the test script, which is just supposed to display some text, I get a blank page (blank in the source too) and no errors reported in the logs.
 
Code:
DocumentRoot "/[URL unfurl="true"]www/servers"[/URL]
ScriptAlias /cgi-bin/ "/home/T28/[URL unfurl="true"]www/servers/cgi-bin/"[/URL]
Is it your intention that cgi bin be off a differnt root?

Code:
<Directory "~/[URL unfurl="true"]www/servers/cgi-bin/">[/URL]

I'm not sure the ~ will resolve to /home/t28

Have you tried explicitly qualifying the directory?

Jeb
\0
 
Code:
DocumentRoot "/[URL unfurl="true"]www/servers"[/URL]
ScriptAlias /cgi-bin/ "/home/T28/www/servers/cgi-bin/"

I thought about this too. is the document root relative to the T28 home, while /home/T28/ is relative to the / directory. I though that / would cause a problem since it isn't absolute, yet the document root works defined like that. Since it's resolving everything (including the cgi-bin folder) just fine, I figured that leaving the docRoot set to that would be okay. Is it actually looking for the script alias in ~/home/T28/servers/cgi-bin/ (something that doesn't exist)? I could have sworn I tried it as / in the past, and had it not work, so I changed it back. In / i do have a symbolic link labled home/T28/www, so regardless if the server is looking in / or ~/, be the same dir.

When I set it that way, I did so because reading through the description I got the impression that in the ScriptAlias section, you could define the folder anywhere in the file system as long as permissions were correct. So I figured that if the folder did not need to a child of the docRoot, it would have to be referenced explicitly.


Code:
<Directory "~/www/servers/cgi-bin/">

That's what I fixed. When I changed it to /home/T28, the permission denied error vanished and it started just throwing up a blank page.
 
If you right click and view source, is that also blank?
And nothing in error_log?

What is the content of your test script?
Something like this?
Code:
#! /usr/bin/perl

print <<EOF;
Content-Type: text/html

<html><head><title>HelloW</title></head><body>
<h3>Hello World</h3></body></html>
EOF
 
That's pretty much the exact code I have as a test.

When I open up the source, I have the standard HTML header stuff, then just empty body tags. So it is returning an HTML page with proper HTML formatting, but absolutly nothing in it.

I'm 99% sure the error log is showing nothing. I'll check it in the morning just to make sure though.
 
try also breaking the script to force an error. If you don't get an error it is probably not calling the script you expect.

You could adjust the access logging to list the full path to the file so you could see how it is resolving the path also.

change this line (with no wrapping)
LogFormat "%h %l %u %t \"%r\" %>s %b ${PATH_TRANSLATED}e" common


 
thanks

I'll try that in the morning. Firewall won't let me SSH in from home. Not sure if that's a good thing or a bad thing.
 
Okay.... here's what's going on now. I thought it might have been an issue with the since the link had T28:users ownership instead of T28:T28, which everything from /home/T28/ has. T28 group has the same permissions as the users group. So I changed the conf file to reference everything from /home/T28

Doing this I started getting error 500, internal server error. in the logs it looks like this:

Code:
[Wed Aug 02 11:20:00 2006] [error] [client 151.159.236.34] (2)No such file or directory: exec of '/home/T28/[URL unfurl="true"]www/servers/cgi-bin/test.pl'[/URL] failed
[Wed Aug 02 11:20:00 2006] [error] [client 151.159.236.34] Premature end of script headers: test.pl

So apparently cgi is attempting to run the script but can't see the file/directroy.

I went back and changed all the references to the / of /home/T28/www, which should produce the same results, as they point to the same directroy. Doing this gives me the same error as before. I even tried combinations, leaving the docRoot as /home/T28 and cgi as /www/ and vice-versa. Neither combo did anything.

I then played with this section of code:
Code:
<Directory "/home/T28/[URL unfurl="true"]www/servers/cgi-bin/">[/URL]
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
    AddHandler cgi-script .cgi .pl
</Directory>

I changed the 'Options' to none and ExecCGI with no change in results as well as commented out the AddHandler. I even tried commenting out the AddHandler here and uncommenting it later in the script.

I'm not exactly sure what I did last night to get it to show the blank page, but going back in my error logs did show that it was giving the same error as before.

anyway, here is my updated conf file just for reference.
Code:
#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:[URL unfurl="true"]http://httpd.apache.org/docs/2.2>[/URL] for detailed information.
# In particular, see 
# <URL:[URL unfurl="true"]http://httpd.apache.org/docs/2.2/mod/directives.html>[/URL]
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "/usr/local/etc/httpd" will be interpreted by the
# server as "/usr/local/etc/httpd/logs/foo.log".

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to point the LockFile directive
# at a local disk.  If you wish to share the same ServerRoot for multiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "/usr/local/etc/httpd"

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#


<IfModule !mpm_netware_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User T28	
Group T28
</IfModule>

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin matthew.beals@gold.sdsmt.edu

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName meso.ias.sdsmt.edu

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/home/T28/[URL unfurl="true"]www/servers"[/URL]

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories). 
#
# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/home/T28/[URL unfurl="true"]www/servers">[/URL]
    #
    # 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
    # [URL unfurl="true"]http://httpd.apache.org/docs/2.2/mod/core.html#options[/URL]
    # 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>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.htm
</IfModule>

#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog logs/error_log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
	#LogFormat "%h %l %u %t \"%r\" %>s %b ${PATH_TRANSLATED}e" common

    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog logs/access_log common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog logs/access_log combined
</IfModule>

<IfModule alias_module>
    #
    # Redirect: Allows you to tell clients about documents that used to 
    # exist in your server's namespace, but do not anymore. The client 
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo [URL unfurl="true"]http://www.example.com/bar[/URL]

    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL.  You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.

    #
    # ScriptAlias: This controls which directories contain server scripts. 
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target 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/ "/home/T28/[URL unfurl="true"]www/servers/cgi-bin/"[/URL]

</IfModule>

<IfModule cgid_module>
    #
    # ScriptSock: On threaded servers, designate the path to the UNIX
    # socket used to communicate with the CGI daemon of mod_cgid.
    #
    #Scriptsock logs/cgisock
</IfModule>

#
# "/usr/local/etc/httpd/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
 
<Directory "/home/T28/[URL unfurl="true"]www/servers/cgi-bin/">[/URL]
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
    #AddHandler cgi-script .cgi .pl
</Directory>


#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig /[URL unfurl="true"]www/conf/mime.types[/URL]

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    #
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    #AddHandler cgi-script .cgi

    # For type maps (negotiated resources):
    #AddHandler type-map var

    #
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml
</IfModule>

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type.  The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
#MIMEMagicFile /[URL unfurl="true"]www/conf/magic[/URL]

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 [URL unfurl="true"]http://www.example.com/subscription_info.html[/URL]
#

#
# EnableMMAP and EnableSendfile: On systems that support it, 
# memory-mapping or the sendfile syscall is used to deliver
# files.  This usually improves server performance, but must
# be turned off when serving from networked-mounted 
# filesystems or if support for these functions is otherwise
# broken on your system.
#
#EnableMMAP off
#EnableSendfile off

# Supplemental configuration
#
# The configuration files in the /[URL unfurl="true"]www/conf/extra/[/URL] directory can be 
# included to add extra features or to modify the default configuration of 
# the server, or you may simply copy their contents here and change as 
# necessary.

# Server-pool management (MPM specific)
#Include /[URL unfurl="true"]www/conf/extra/httpd-mpm.conf[/URL]

# Multi-language error messages
#Include /[URL unfurl="true"]www/conf/extra/httpd-multilang-errordoc.conf[/URL]

# Fancy directory listings
#Include /[URL unfurl="true"]www/conf/extra/httpd-autoindex.conf[/URL]

# Language settings
#Include /[URL unfurl="true"]www/conf/extra/httpd-languages.conf[/URL]

# User home directories
#Include /[URL unfurl="true"]www/conf/extra/httpd-userdir.conf[/URL]

# Real-time info on requests and configuration
#Include /[URL unfurl="true"]www/conf/extra/httpd-info.conf[/URL]

# Virtual hosts
#Include /[URL unfurl="true"]www/conf/extra/httpd-vhosts.conf[/URL]

# Local access to the Apache HTTP Server Manual
#Include /[URL unfurl="true"]www/conf/extra/httpd-manual.conf[/URL]

# Distributed authoring and versioning (WebDAV)
#Include /[URL unfurl="true"]www/conf/extra/httpd-dav.conf[/URL]

# Various default settings
#Include /[URL unfurl="true"]www/conf/extra/httpd-default.conf[/URL]

# Secure (SSL/TLS) connections
#Include /[URL unfurl="true"]www/conf/extra/httpd-ssl.conf[/URL]
#
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
 
one other thing I figurd out through trial and error.

If I go into the actual server root directory and place a symbolic link there to the cgi-bin dir in the document root, then change the httpd.conf file so that the cgi-bin folder is just "cgi-bin/" (meaning it looks for the folder in the server root), then the error changes over to:

Code:
[Wed Aug 02 14:10:43 2006] [error] [client 151.159.236.34] client denied by server configuration: /usr/local/etc/httpd/cgi-bin/test.pl
 
The error
No such file or directory: exec of '/home/T28/ failed
is caused when apache can't find the perl interpreter. The line ending on the shebang #! /usr/bin/perl line does not have the proper new line character.

To resolve this you need to change the line endings from windows style \r\n to *nix style \n. Many editors have a facility for this. Notepad does not!

PSPad (free) makes this easy. Format on the main menu lets you choose.

You can confirms this by creating a short perl script using vi. Trying to change them from \r\n to \n with vi is not obvious. I never figured it out!

After a couple of these, you will never forget it.

Jeb
\0
 
Thank you so much. That's what was doing it. I had been doing everything from my windows laptop via Secure Shell. I just opened the .pl file on the linux box, backspaces the newline chars and put them back in. Now it's working fine.

I would have never in a million years figured that one out.

thanks again.
 
vortmax,
Thanks for the vote.

Yes this drove me nuts for a little while.

You can also test cgi scripts from an ssh command window. It can help by removing any apache side effects and isolating other permissions/execution errors.

Jeb Beasley
\0
 
do you mean test scripts by just typing in ./scriptName?

I could execute the script without problems using 'perl script', but I assume that cicumvented the \r\n issue as I was telling it in the command where perl was.
 
Yes, ./testcgi.pl Shell will read the shebang and call the appropriate interpreter. #! /bin/bash works for .sh script #! /usr/bin/python, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top