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

Problem starting CGI in Apache

Status
Not open for further replies.

Donboy

IS-IT--Management
Aug 20, 2002
73
US
I've got Apache working fine. I'm able to serve pages using it. I've also been to a friend's house and seen my site, so I know Apache is running, dispite the fact that I have not given apache a "servername" directive. The line has been commented out the whole time, but somehow it still works! I'm really not sure why it works, but I can give you the IP address right now and you can see my pages. But anyway, that's not my problem.

I'm trying to get CGI working and I'm having some trouble. I've got SSI tags that are embedded in my index page that are calling CGI scripts, but I always get [Unable to include] messages on those pages. In the error log, all I get is "Premature end of script headers" which tells me nothing. I have also CHMOD all my scripts to 755 so I know that's not the problem.

I have done a "whereis perl" and it returned a couple of paths, but the one that seemed most likely was /usr/bin/perl. When I checked this path, there was no folder named perl under /usr/bin, so now I'm really confused.

The place where Perl seems to be most likely located (just from my browsing the folders) is /usr/lib/perl5 because there are a few folders under here, namely one called 5.8.0 and under that folder I see several .pm modules, so this seems like the right place. However, I've tried using this path for the shebang line of of my scripts, but it's still not working; I get the same permature end of script headers message in the error log. I've also tried /usr/lib/perl5/5.8.0 just for good measure, but not luck.

Here is my config file in all its glory. Please tell me if anyone sees any glaring mistakes. Commented lines removed for clarity except those that are directives that have been commented out so that you can see they are actually present but I'm not using them.

Thanks in advance!


ServerTokens OS

ServerRoot "/etc/httpd"

#ScoreBoardFile run/httpd.scoreboard

PidFile run/httpd.pid

Timeout 300

KeepAlive Off

MaxKeepAliveRequests 100

KeepAliveTimeout 15

<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
MaxClients 150
MaxRequestsPerChild 1000
</IfModule>

<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

<IfModule perchild.c>
NumServers 5
StartThreads 5
MinSpareThreads 5
MaxSpareThreads 10
MaxThreadsPerChild 20
MaxRequestsPerChild 0
</IfModule>

#Listen 12.34.56.78:80
Listen 80

Include conf.d/*.conf

LoadModule access_module modules/mod_access.so
LoadModule auth_module modules/mod_auth.so
LoadModule auth_anon_module modules/mod_auth_anon.so
LoadModule auth_dbm_module modules/mod_auth_dbm.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule mime_magic_module modules/mod_mime_magic.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 unique_id_module modules/mod_unique_id.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule asis_module modules/mod_asis.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule imap_module modules/mod_imap.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so

<IfModule prefork.c>
LoadModule cgi_module modules/mod_cgi.so
</IfModule>

<IfModule worker.c>
LoadModule cgid_module modules/mod_cgid.so
</IfModule>

#ExtendedStatus On

User apache
Group apache

ServerAdmin webmaster@nexuscity.net

#ServerName 192.168.0.50:80

UseCanonicalName Off

DocumentRoot &quot;/home/donboy/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

<Directory &quot;/home/donboy/ Options Indexes Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<Directory &quot;/home/donboy/ AllowOverride None
Options +ExecCGI
</Directory>

<LocationMatch &quot;^/$>
Options Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>

<IfModule mod_userdir.c>
UserDir disable
#UserDir public_html
</IfModule>

DirectoryIndex index.html index.html.var

AccessFileName .htaccess

<Files ~ &quot;^\.ht&quot;>
Order allow,deny
Deny from all
</Files>

TypesConfig /etc/mime.types

DefaultType text/plain

<IfModule mod_mime_magic.c>
# MIMEMagicFile /usr/share/magic.mime
MIMEMagicFile conf/magic
</IfModule>

HostnameLookups Off

ErrorLog logs/error_log

LogLevel warn

LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %>s %b \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot;&quot; combined
LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %>s %b&quot; common
LogFormat &quot;%{Referer}i -> %U&quot; referer
LogFormat &quot;%{User-agent}i&quot; agent

# CustomLog logs/access_log common
CustomLog logs/access_log combined

#CustomLog logs/referer_log referer
#CustomLog logs/agent_log agent

#CustomLog logs/access_log combined

ServerSignature On

Alias /icons/ &quot;/var/
<Directory &quot;/var/ Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

Alias /manual &quot;/var/
<Directory &quot;/var/ Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

<IfModule mod_dav_fs.c>
# Location of the WebDAV lock database.
DAVLockDB /var/lib/dav/lockdb
</IfModule>

ScriptAlias /cgi-bin/ &quot;/home/donboy/
<IfModule mod_cgid.c>
Scriptsock run/httpd.cgid
</IfModule>

<Directory &quot;/home/donboy/ AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

IndexOptions FancyIndexing VersionSort NameWidth=*

AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*

AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core

AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^

DefaultIcon /icons/unknown.gif

ReadmeName README.html
HeaderName HEADER.html

IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

AddEncoding x-compress Z
AddEncoding x-gzip gz tgz

AddLanguage da .dk
AddLanguage nl .nl
AddLanguage en .en
AddLanguage et .et
AddLanguage fr .fr
AddLanguage de .de
AddLanguage he .he
AddLanguage el .el
AddLanguage it .it
AddLanguage ja .ja
AddLanguage pl .po
AddLanguage kr .kr
AddLanguage pt .pt
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pt-br .pt-br
AddLanguage ltz .ltz
AddLanguage ca .ca
AddLanguage es .es
AddLanguage sv .se
AddLanguage cz .cz
AddLanguage ru .ru
AddLanguage tw .tw
AddLanguage zh-tw .tw
AddLanguage hr .hr

LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ltz ca es sv tw

ForceLanguagePriority Prefer Fallback

AddDefaultCharset ISO-8859-1

AddCharset ISO-8859-1 .iso8859-1 .latin1
AddCharset ISO-8859-2 .iso8859-2 .latin2 .cen
AddCharset ISO-8859-3 .iso8859-3 .latin3
AddCharset ISO-8859-4 .iso8859-4 .latin4
AddCharset ISO-8859-5 .iso8859-5 .latin5 .cyr .iso-ru
AddCharset ISO-8859-6 .iso8859-6 .latin6 .arb
AddCharset ISO-8859-7 .iso8859-7 .latin7 .grk
AddCharset ISO-8859-8 .iso8859-8 .latin8 .heb
AddCharset ISO-8859-9 .iso8859-9 .latin9 .trk
AddCharset ISO-2022-JP .iso2022-jp .jis
AddCharset ISO-2022-KR .iso2022-kr .kis
AddCharset ISO-2022-CN .iso2022-cn .cis
AddCharset Big5 .Big5 .big5
# For russian, more than one charset is used (depends on client, mostly):
AddCharset WINDOWS-1251 .cp-1251 .win-1251
AddCharset CP866 .cp866
AddCharset KOI8-r .koi8-r .koi8-ru
AddCharset KOI8-ru .koi8-uk .ua
AddCharset ISO-10646-UCS-2 .ucs2
AddCharset ISO-10646-UCS-4 .ucs4
AddCharset UTF-8 .utf8

AddCharset GB2312 .gb2312 .gb
AddCharset utf-7 .utf7
AddCharset utf-8 .utf8
AddCharset big5 .big5 .b5
AddCharset EUC-TW .euc-tw
AddCharset EUC-JP .euc-jp
AddCharset EUC-KR .euc-kr
AddCharset shift_jis .sjis

AddType application/x-tar .tgz

AddHandler cgi-script .cgi .pl

#AddHandler send-as-is asis

AddHandler imap-file map

AddHandler type-map var

AddOutputFilter INCLUDES .html .shtml

Alias /error/ &quot;/var/
<IfModule mod_negotiation.c>
<IfModule mod_include.c>
<Directory &quot;/var/ AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Order allow,deny
Allow from all
LanguagePriority en es de fr
ForceLanguagePriority Prefer Fallback
</Directory>

ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var

</IfModule>
</IfModule>

BrowserMatch &quot;Mozilla/2&quot; nokeepalive
BrowserMatch &quot;MSIE 4\.0b2;&quot; nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch &quot;RealPlayer 4\.0&quot; force-response-1.0
BrowserMatch &quot;Java/1\.0&quot; force-response-1.0
BrowserMatch &quot;JDK/1\.0&quot; force-response-1.0
BrowserMatch &quot;Microsoft Data Access Internet Publishing Provider&quot; redirect-carefully
BrowserMatch &quot;^WebDrive&quot; redirect-carefully
 
I don't know if this is causing your problem, but it's wrong so let's get it fixed. You have your cgi-bin defined twice. Once without the ScriptAlias directive and once with it. You also have your cgi-bin inside of your DocumentRoot. This is not the end of the world but I'll tell you why doing it this way is kinda funky. The ScriptAlias directive does two things. First, it tells apache to treat everything in that directory as a script. This is why you don't usually put html pages in your cgi-bin. The second thing it does is tells apache to pretend the cgi-bin directory is in your DocumentRoot (See what I mean?). When you define the cgi-bin directory, you use the true path but apache will show the url as Here is what I think may be your problem. Pages with ssi in them must have the shtml extension. The pages should NOT be in the cgi-bin. You will need the +ExecCGI option in the directory container where your .shtml files are. I may have missed something but dinner is ready and I'm starving. Hope you get it figured out.
 
For the 2 definitions of cgi-bin, I think you must be talking about these seemingly extra lines...

<Directory &quot;/home/donboy/ AllowOverride None
Options +ExecCGI
</Directory>

I added these in an attempt to further demonstrate to Apache where I wanted my cgi-bin to be only after having some problems making it work. I had a feeling it needed the ExecCGI option, so that's the only reason it appears there. I have just tested by removing these lines and it doesn't help.

The reason I put my cgi-bin under the document root is because I didn't want to do any fancy linking within Unix and I wanted to be able to FTP into the server and find my cgi-bin located under the document root (a very logical place to look for it). I'm currently being hosted by another service and when I FTP into the account, my cgi-bin is found under my document root, so I don't understand why that would be a problem. If they can do it, why can't I?

Anyway, I have just changed my ScriptAlias to /var/ and restarted Apache. I know my changes worked because now I see a different error message. In my document root, I have .htaccess files to redirect the user to custom error pages. Now that I've changed the cgi-bin to reside under /var/ I'm getting a different error message. Now I'm getting Apache's plain ol' 500 error page.

With that said, I'm getting the idea that Apache is doing its job just fine, but I've got something else wrong. For my CGI scripts, I have all of them set to my username as the owner, but what about the group? Does that matter? Maybe you can advise me on how to determine the correct shebang line? On my current host, if I got the shebang line wrong, the error is more descriptive telling me that Perl could not be found under the location I was asking for. This is a very vauge message: &quot;Premature end of script headers&quot;.

You said that pages with SSI callouts must have the .shtml extension. My desire is to have .html files read as SSI documents too. And yes, I realize this is a extra strain on the server and probably a security risk too, but I'm willing to live with that. I have numerous pages created with SSI tags embedded into .html documents and I'd rather not go back and rework all of those links to be .shtml instead.

Could you tell if I'm doing that properly in the config file? I'm using the line...

AddOutputFilter INCLUDES .html .shtml

You also said that I will need the +ExecCGI option in the directory where my SSI documents are. If that's true, then I will need to make my document root and all sub-folders enabled with +ExecCGI. I believe this is done by going to the <Directory> statement where I define my document root and adding ExecCGI as one of the options. Is that correct? Just want to make sure I really understand what's going on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top