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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI scripts not being found

Status
Not open for further replies.

Shodan44

Programmer
Apr 15, 2002
4
AU
Greetings. I am running Apache 1.3.9 and am having a great deal of trouble in getting CGI scripts to run. I am constantly getting the "500 Internal server error" page. The error.log is always saying exec failed because the file or dirtory does not exist. E.G.

[Sun Apr 14 06:56:03 2002] [error] (2)No such file or directory: exec of /usr/lib/cgi-bin/test.cgi failed
[Sun Apr 14 06:56:03 2002] [error] [client 192.168.0.1] Premature end of script headers: /usr/lib/cgi-bin/test.cgi


I even made it so my DocumentRoot (/var/www) could execute CGI scripts but I still get the same error message, of course pertaining to /var/www. The script I'm testing is fine because it prints out HTML when I run it from the shell.

The pertinent lines from my conf files are:

srm.conf:

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

AddHandler cgi-script .cgi .pl


access.conf:


<Directory /cgi-bin/>
AllowOverride None
Options ExecCGI FollowSymLinks
Allow from all
</Directory>



HTTPD runs itself as User: &quot; & Group: &quot; does that mean the cgi-bin directory and scripts have to be owned by and in the group (In any case I've tried changing owner and group but no joy!!) When I type &quot;which perl&quot; I get back &quot;/usr/bin/perl&quot; which is what I have at the top of my test.cgi script. Also my cgi-bin directory and test script has been chmoded to 777.

I've ploughed through many of the old posts relating to running CGI scripts but can't find anything that gives me a possible answer to this problem. I believe I must be missing something fairly basic because there doesn't seem to be all that much to getting CGI running on APACHE and everything looks ok to me! Could anyone suggest some things to take a look at? Any help would be greatly appreciated!

Thanks

Shodan44
 
I have the settings that you show in red, in my httpd.conf file, not the other files. Change the httpd.conf file to mirror what you have posted and it should work.
 
I have the settings that you show in red, in my httpd.conf file, not the other files. Change the httpd.conf file to mirror what you have posted and it should work.

I hate to contradict you again mate [wink] but you both have totally different setups. Shodan44 is including these files in the httpd.conf and you are not..

Just because yours is set up a certain way and all config is included in the httpd.conf, does not mean that all apache servers are the same and use the same method as you.. You will find that they are not..

Hope this helps Wullie

 
So it looks like I have got the correct setup! Why would APACHE keep saying it can't find the file though? I took out the &quot;#!&quot; in front of the path to perl at the top of my test script and the error that came up was something like Exec faild: Script format error. That tells me it DOES find the script and trys to run it, but why, when it is formatted correctly does it say &quot;No such file or directory&quot;!! Very frustrating, at least I know my config is on the right track. [smile]

Shodan44
 
Here is the script:

#!/usr/bin/perl

print &quot;Content-type: text/html\n\n&quot;;

print &quot;Hello World&quot;;

As you can see its pretty basic, thats why I don't see why it won't run!

Shodan44
 
I see you're having the same problem as me Shodan44. I added these lines to my conf file and I still can't get it to work:

ScriptAlias /cgi-bin/ &quot;/var/
<Directory /var/ AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

I'm going to try what wullie posted - just changing that one line: Option ExecCGI to Option None

Question wullie: Would it matter if I changed the port that I'm running Apache on? I wouldn't think so but I thought I would ask. I just want to cover all the bases here.
 
Here is my httpd.conf, and thanks wullie for taking the time to have a look:



### Main Configuration Section
### You really shouldn't change these settings unless you're a guru
###
ServerType standalone
ServerRoot /etc/httpd
#ServerName localhost
#LockFile /etc/httpd/httpd.lock
PidFile /var/run/httpd.pid
ScoreBoardFile /etc/httpd/httpd.scoreboard
ErrorLog logs/error_log
LogLevel warn
ResourceConfig /dev/null
AccessConfig /dev/null

### Dynamic Shared Object (DSO) Support
###
###
#LoadModule mmap_static_module modules/mod_mmap_static.so
LoadModule env_module modules/mod_env.so
LoadModule config_log_module modules/mod_log_config.so
LoadModule agent_log_module modules/mod_log_agent.so
LoadModule referer_log_module modules/mod_log_referer.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule status_module modules/mod_status.so
LoadModule info_module modules/mod_info.so
LoadModule includes_module modules/mod_include.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule asis_module modules/mod_asis.so
LoadModule imap_module modules/mod_imap.so
LoadModule action_module modules/mod_actions.so
#LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule proxy_module modules/libproxy.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule access_module modules/mod_access.so
LoadModule auth_module modules/mod_auth.so
LoadModule anon_auth_module modules/mod_auth_anon.so
#LoadModule dbm_auth_module modules/mod_auth_dbm.so
#LoadModule db_auth_module modules/mod_auth_db.so
LoadModule digest_module modules/mod_digest.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule example_module modules/mod_example.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
<IfDefine HAVE_SSL>
LoadModule ssl_module extramodules/libssl.so
</IfDefine>
<IfDefine HAVE_PHP4>
LoadModule php4_module extramodules/libphp4.so
</IfDefine>
LoadModule vhost_alias_module modules/mod_vhost_alias.so

# Reconstruction of the complete module list from all available modules
# (static and shared ones) to achieve correct module execution order.
# [WHENEVER YOU CHANGE THE LOADMODULE SECTION ABOVE UPDATE THIS, TOO]
ClearModuleList
#AddModule mod_mmap_static.c
AddModule mod_env.c
AddModule mod_log_config.c
AddModule mod_log_agent.c
AddModule mod_log_referer.c
#AddModule mod_mime_magic.c
AddModule mod_mime.c
AddModule mod_negotiation.c
AddModule mod_status.c
AddModule mod_info.c
AddModule mod_include.c
AddModule mod_autoindex.c
AddModule mod_dir.c
AddModule mod_cgi.c
AddModule mod_asis.c
AddModule mod_imap.c
AddModule mod_actions.c
#AddModule mod_speling.c
AddModule mod_userdir.c
AddModule mod_proxy.c
AddModule mod_alias.c
AddModule mod_rewrite.c
AddModule mod_access.c
AddModule mod_auth.c
AddModule mod_auth_anon.c
#AddModule mod_auth_dbm.c
#AddModule mod_auth_db.c
AddModule mod_digest.c
#AddModule mod_cern_meta.c
AddModule mod_expires.c
AddModule mod_headers.c
AddModule mod_usertrack.c
#AddModule mod_example.c
#AddModule mod_unique_id.c
AddModule mod_so.c
AddModule mod_setenvif.c
<IfDefine HAVE_SSL>
AddModule mod_ssl.c
</IfDefine>
<IfDefine HAVE_PHP4>
AddModule mod_php4.c
</IfDefine>
AddModule mod_vhost_alias.c

###
### Global Configuration
###
# We now support multiple apache configurations on the same server. In
# common.conf, we put all directives that are common to all implementations
# (httpd, httpd-perl, etc.)
Include conf/commonhttpd.conf


###
### IP Address/Port and Proxied configuration section
###
# The APACHEPROXIED setting can be set in /etc/rc.d/init.d/httpd if you
# are using a proxy or accelerator, like the Apache-SGI or khttpd, so that
# the fast web server serves static content while Apache handles the
# cgi or php files

#BindAddress *
<IfDefine !APACHEPROXIED>
Port 80
Listen 8000
</IfDefine>
<IfDefine APACHEPROXIED>
Port 8080
Listen 8080
</IfDefine>

# Likewise, we can set apache as the server by default and send perl
# requests via ProxyPass to apache-mod_perl. It increases performance
# since the perl interpreter is only used for perl and the standard apache
# does all the html and image files, with a smaller footprint.
#
# If you install apache and apache-mod_perl, this is the default config.
# If you don't want two web servers to use perl, uninstall apache, and
# apache-mod_perl will not be proxied.

<IfDefine PERLPROXIED>
RewriteEngine on
RewriteRule ^proxy:.* - [F]
RewriteRule ^(.*\/perl\/.*)$ [P]
RewriteRule ^(.*\/cgi-perl\/.*)$ [P]
</IfDefine>

###
### Log configuration Section
###

#Single logfile with access, agent and referer information
#This is the default, if vlogs are not defined for the main server
CustomLog logs/access_log combined env=!VLOG
#If VLOG is defined in conf/vhosts/Vhost.conf, we use this entry
CustomLog &quot;|/usr/sbin/advxsplitlogfile&quot; vhost env=VLOG


###
### Virtual Hosts
###
# We include different templates for Virtual Hosting. Have a look in the
# vhosts directory and modify to suit your needs.
Include conf/vhosts/Vhosts.conf
#Include conf/vhosts/DynamicVhosts.conf
#Include conf/vhosts/VirtualHomePages.conf


###
### Performance settings Section
###
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to &quot;Off&quot; to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15

#
# Server-pool size regulation. Rather than making you guess how many
# server processes you need, Apache dynamically adapts to the load it
# sees --- that is, it tries to maintain enough server processes to
# handle the current load, plus a few spare servers to handle transient
# load spikes (e.g., multiple simultaneous requests from a single
# Netscape browser).
#
# It does this by periodically checking how many servers are waiting
# for a request. If there are fewer than MinSpareServers, it creates
# a new spare. If there are more than MaxSpareServers, some of the
# spares die off. The default values are probably OK for most sites.
#
MinSpareServers 4
MaxSpareServers 10

#
# Number of servers to start initially --- should be a reasonable ballpark
# figure.
#
StartServers 4

#
# Limit on total number of servers running, i.e., limit on the number
# of clients who can simultaneously connect --- if this limit is ever
# reached, clients will be LOCKED OUT, so it should NOT BE SET TOO LOW.
# It is intended mainly as a brake to keep a runaway server from taking
# the system with it as it spirals down...
#
MaxClients 150

#
# MaxRequestsPerChild: the number of requests each child process is
# allowed to process before the child dies. The child will exit so
# as to avoid problems after prolonged use when Apache (and maybe the
# libraries it uses) leak memory or other resources. On most systems, this
# isn't really needed, but a few (such as Solaris) do have notable leaks
# in the libraries. For these platforms, set to something like 10000
# or so; a setting of 0 means unlimited.
#
# NOTE: This value does not include keepalive requests after the initial
# request per connection. For example, if a child process handles
# an initial request and 10 subsequent &quot;keptalive&quot; requests, it
# would only count as 1 request towards this limit.
#
MaxRequestsPerChild 500

Include conf/ssl/mod_ssl.conf
Include conf/ssl/ssl.default-vhost.conf
Include conf/addon-modules/php.conf

#I added from this line and below
AddType image/x-icon .ico
ScriptAlias /cgi-bin/ &quot;/var/
<Directory &quot;/var/ AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
 
Thanks for the suggestion &quot;<Directory /cgi-bin>&quot; Wullie, but I'm still having no luck.

Mithrilhall, from what I can see from the original conf files that came with my version of apache, if you have the line:

ScriptAlias /cgi-bin/ /var/

then where you define (Probably don't have to when using script alias) the cgi-bin directory, you should be using the alias not the full path. ie.

<Directory /SCRIPTALIAS_NAME/>
blah blah blah
blah blah blah
blah blah blah
</Directory>

Anyway, there is a comment in my access.conf which relates to the above and says something like &quot;Please change /usr/lib/cgi-bin to whatever you scriptaliased directory is, if you have that configured&quot;.

I have a feeling that my config files and Mithrilhall's files are fine but that there is something else.

Mithrilhall, take the &quot;#!/usr/bin/perl&quot; from the top of your test script and I bet the error that comes up in the error.log says something like &quot;Exec failed: Script format error&quot;.

Thats what it does on mine when I take that line out of the script, that tells me apache can see the file and tries to run it. Why then isn't it found when the script IS formatted correctly... Arrrrgh [mad]

Shodan44
 
Shodan,

<Directory /SCRIPTALIAS_NAME/> should be the actual directory and not the alias. That was just an example that I posted.. But, on the other hand, if you are getting alternate errors depending on what you do then apache must be finding the file..

Are you also using virtualhosts?

Hope this helps Wullie

 
Also, you could try the following script which should tell you the server enviromental information.

#!/usr/bin/perl
print &quot;Content-type: text/html\n\n&quot;;
foreach $key (keys %ENV) {
print &quot;$key --> $ENV{$key}<br>&quot;;
}

If this doesn't work and you are running virtualhosts then I think that I know the problem so please post the data of your virtualhosts here..

Hope this helps Wullie

 
I'm pretty sure I don't have virtualhosts running. Is there any way for me to check to make sure?

Shodan44, I'll try what you said by taking out the line &quot;#!/usr/bin/perl&quot; as soon as my dsl is back up. I'm at work and unable to access my box.
 
Hi mate,

The reason that I asked about virtualhosts is because you are including this file into your httpd.conf. Also, is there a reason that your server root and cgi-bin are in totally different locations?

Because the virtualhosts are not the problem, could you post your commonhttpd.conf here also?

Hope this helps Wullie

 
Well, after updating my Mandrake 8.1 to 8.2 Apache seems to have stoped working. I attempted at installing Apache 2.0 but that didn't work either so I'm going to install Mandrake 8.2 fresh when I get home. Maybe this will help get my cgi-bin to start working correctly. If not I'll post the contents of my commonhttpd.conf file.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top