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

cgi scripts don't run on apache/perl installed on WinXP Pro

Status
Not open for further replies.

HeatherFeuer

Technical User
Jan 3, 2002
19
US
I recently installed Perl 5.8.007 that comes with a fairly complete packed except for mySQL. I have it installed with virtual hosts for Apache (the main server) and two other websites that I maintain. I like being able to test scripts on my local WinXP Pro machine. I have service pack one and all the current updates except for Service Pack 2 -- haven't felt the need for it.

My server installation accepts and runs all the html documents for all the configured sites. However, I can't get any of my cgi or perl scripts to run. I have followed the directions for adding paths and the script(s) have the correct path to Perl. My httpd.conf file includes "AddHandler cgi-script .cgi .pl" (without the quotes).

What am I forgetting or doing wrong?

Heather
 
Are you getting any errors to the browser or in your httpd.log?

In your httpd.conf file, you should have a section that defines the location of you cgi-bin. Mine looks like...

Code:
#
# 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/ "C:/myUserName/apache/cgi-bin/"

#
# "C:/Program Files/Apache Group/Apache2/cgi-bin" 
# should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "C:/myUserName/apache/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>



You should be able to place a piece of CGI code in that dir and hit it from a browser. I saved the following in my cgi-bin (c:/myUserName/apache/cgi-bin/) and named it 'simple_cgi.cgi'.
Code:
#!perl
use CGI;

my $http = new CGI;
print $http->header,
	$http->start_html,
	qq(<p>Some content here</p>),
	$http->end_html;

I then went to and saw 'Some content here'.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thanks for the response, goboating.

I still can't get any of my scripts to be recognized. In the browser, I get a 404. In my error log I get the following:

"[Wed May 18 21:18:03 2005] [error] [client 000.000.0.000] script not found or unable to stat: E:/WebServer/Apache2/cgi-bin/clickable-image.cgi"

I masked the IP. It is a static IP address for the computer Apache is installed on. Here is the script I have been using to troubleshoot:


Code:
#!E:/Webserver/Perl/bin/Perl.exe

use CGI;
$query = new CGI;
print $query->header;
print $query->start_html("A Clickable Image");
print <<END;
<H1>A Clickable Image</H1>
</A>
END
print "Sorry, this isn't very exciting!\n";

print $query->startform;
print $query->image_button('picture',"./wilogo.gif");
print "Give me a: ",$query->popup_menu('letter',['A','B','C','D','E','W']),"\n"; # 
print "<P>Magnification: ",$query->radio_group('magnification',['1X','2X','4X','20X']),"\n";
print "<HR>\n";

if ($query->param) {
    print "<P>Magnification, <EM>",$query->param('magnification'),"</EM>\n";
    print "<P>Selected Letter, <EM>",$query->param('letter'),"</EM>\n";
    ($x,$y) = ($query->param('picture.x'),$query->param('picture.y'));
    print "<P>Selected Position <EM>($x,$y)</EM>\n";
}

print $query->end_html;

On the first line, I have tried everything from #!Perl to perl.exe all the way to what you see now. I can't seem to get apache to recognize any perl or cgi scripts. Here is the script alias and directory for .cgi from my httpd.conf file:


Code:
ScriptAlias /cgi-bin/ "E:/WebServer/Apache2/cgi-bin/"

#
# "@@ServerRoot@@/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "E:/WebServer/Apache2/cgi-bin/">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

Here is the list of LoadModule directives from my httpd.conf file:

Code:
LoadModule access_module modules/mod_access.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_module modules/mod_auth.so
LoadModule autoindex_module modules/mod_autoindex.so
[b]LoadModule cgi_module modules/mod_cgi.so[/b]
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule imap_module modules/mod_imap.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule info_module modules/mod_info.so
LoadModule status_module modules/mod_status.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 cern_meta_module modules/mod_cern_meta.so
#LoadModule dav_module modules/mod_dav.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule expires_module modules/mod_expires.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule headers_module modules/mod_headers.so
#LoadModule info_module modules/mod_info.so
#LoadModule rewrite_module modules/mod_rewrite.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule status_module modules/mod_status.so
#LoadModule unique_id_module modules/mod_unique_id.so
#LoadModule usertrack_module modules/mod_usertrack.so

So I know the cgi module has been loaded. I'm really stumped. When I had apache server running under Win2K, I never had this problem! Any further suggestions would be greatly appreciated!

Heather
 
First, I play on Linux a whole lot more than in Windows. So, I'm probably not the best person to help but...

From what I can tell, your conf file looks reasonable. My first suspicion is that the webserver may not have sufficient permissions to see, what I assume is, a network drive (E:).

I'd try temporarily putting my cgi-bin on my c drive just long enough to make it work. Then when you're sure the conf file is working and the Perl/CGI stuff is working, you can move the cgi-bin to another more appropriate location and modify your conf file accordingly.

It has been a while since I installed Apache2 on my XP box, but it seems that all I had to do was add the ScriptAlias definitions to the conf file and restart apache.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Hi goboating,

My E: drive is a local drive on my own desktop. I am on a local network, but it is a simple peer-to-peer setup. The server recognizes .html pages and .php just fine. Even when I set up virtual hosts and very clearly do a script alias to point to the virtual host's cgi-bin, it still won't recognize that cgi-bin.

I have a feeling that I am missing something in the server configuration. If the server doesn't recognize .cgi files, I haven't even gotten to the point of premature script end that would indicate something wrong in the header. I'm about at the point where I think I'm going to uninstall this version and go back to the previous version that I was running when I was using the Win2k OS. I didn't have any problems with that version.

Heather
 
Hi, goboating!

I ended up reinstalling everything using the .msi binaries. The installation process was much different than the .exe binary and was much smoother. I guess that installation corrected whatever was going on with the previous install because now I can get my cgi scripts to work! Yay!

Now I have a problem with a script being run by one of my virtual hosts. I've made sure all the paths are correct. The program is a site search engine. I was able to run the setup.cgi file alright and the final screen had a link to the admin.cgi so that I could configure the program in more detail. I can get to the login screen just fine. But once I type in my user name and password and hit the login button, the next screen refuses to load and my error log gives me "premature end of script headers" error.

Here is the first part of the cgi script where it sets everying up:
Code:
#!e:/webserver/perl/bin/perl.exe
 
########################################################################
# COPYRIGHT NOTICE:
#
# Copyright 2002 FocalMedia.Net All Rights Reserved.
#
# Selling the code for this program without prior written consent 
# from FocalMedia.Net is expressly forbidden. You may not 
# redistribute this program in any shape or form.
# 
# This program is distributed "as is" and without warranty of any
# kind, either express or implied. In no event shall the liability 
# of FocalMedia.Net for any damages, losses and/or causes of action 
# exceed the total amount paid by the user for this software.
#
########################################################################

use FindBin;
use lib $FindBin::Bin;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use acs;

### WINDOWS USERS EDIT BELOW ##############################################
#$cfile = "config.cfg";
$cfile = "e:/websites/larleegenealogy/cgi-bin/fmsearch/config.cfg";
###########################################################################

$version = "FM SiteSearch Pro Version 2.0.1";

&get_setup;
$q = CGI->new;

$default_permissions = 0777;  ### DEFAULT PERMISSIONS THAT IS USED FOR DATA FILES IN DATA DIRECTORY

#####
#$setupcrit = &get_setup;
#($data_dir, $web_url, $script_url, $username, $password, $webroot) = split (/\t/, $setupcrit);
#####

acs::check_access($username, $password, $q->param('username'), $q->param('password'));
$template = acs::gtemplate("ctl");


##################################################################################

if ($q->param('fct') eq "stats") {&stats; exit;}
if ($q->param('fct') eq "mysearch") {&mysearch;}

print "Content-type: text/html\n\n";

#################################################################################

if ($q->param('fct') eq "") {&start;}
if ($q->param('fct') eq "what_search") {&what_search;}
if ($q->param('fct') eq "what_search1") {&what_search1;}
if ($q->param('fct') eq "what_search2") {&what_search2;}
if ($q->param('fct') eq "save_dirs") {&save_dirs;}
if ($q->param('fct') eq "search_settings") {&search_settings;}
if ($q->param('fct') eq "save_ss") {&save_ss;}
if ($q->param('fct') eq "html_code") {&html_code;}
if ($q->param('fct') eq "upgrade") {&tmplup;}
if ($q->param('fct') eq "templates") {&template_scr;}
if ($q->param('fct') eq "template_edit") {&template_edit;}
if ($q->param('fct') eq "save_template") {&save_template;}
if ($q->param('fct') eq "save_dirs2") {&save_dirs2;}

Can you see something I'm missing?

Thanks!

Heather
 
looks like $username and $password have not been defined before trying to run acs::check_access?

Code:
#####
#$setupcrit = &get_setup;
#($data_dir, $web_url, $script_url, $username, $password, $webroot) = split (/\t/, $setupcrit);
#####

acs::check_access($username, $password, $q->param('username'),

kind of silly to load the CGI module and then manually print an http header:

print "Content-type: text/html\n\n";

use should also be using the "strict" pragma:

use strict;

at the beginning of your script to avoid typos and other mistakes that could be hard to debug later on,
 
looks like $username and $password have not been defined before trying to run acs::check_access?

So I should uncomment those two lines?

I already put "use strict;" (without the quotes) as well as "use warnings;" What came back totally confused me! It all consisted of the same error on different lines! Here is a sample:

Code:
Global symbol "$cfile" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 29.
Global symbol "$version" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 32.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 35.
Global symbol "$default_permissions" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 37.
Global symbol "$username" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 44.
Global symbol "$password" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 44.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 44.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 44.
Global symbol "$template" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 45.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 50.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 51.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 57.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 58.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 59.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 60.
Global symbol "$q" requires explicit package name at E:/Websites/LarleeGenealogy/cgi-bin/fmsearch/admin.cgi line 61.

About the only thing I could see wrong was using double quotes so I changed them all to single quotes and got the SAME errors. I changed them back to double quotes and either way get the same errors.

Maybe I just don't understand cgi well enough, I don't know. I DO know that the scripts work fine on my web host running Linux Red Hat and Apache/Perl. But on my windows machine, I am having a terrible time!

Heather
 
I can be a hassle to get rid of all those "requires explicit package" errors when converting an script to use strict.

So I should uncomment those two lines?

I have no idea, but you could try and see if it helps. The maker of the script has a website and help forums so maybe asking there would be a good idea.

 
I can..." in my previous post should have been "It can...." ;-)
 
Yeah I know the script maker has a website and all that. But their support forum is "down for maintenance." I am using the "free" version, so although I've opened a trouble ticket, its priority is bottom of the totem pole behind any and all trouble tickets submitted by paying customers. That means I'll probably hear back next week sometime. So I guess I'm on my own trying to figure this out...

Heather
 
maybe the script works good, I don't want to bash the script or it's author(s), but the sample of the code you posted doesn't inspire confidence that it's a well written script.
 
Well, after pulling my hair out all day, I went back to the site and downloaded the lastest version which is supposed to address the login issue.

The problem NOW is that for some reason the admin.exe script does get the correct "&script_url/admin.cgi." The correct URL as listed in the config.cfg file is /admin.cgi but instead its loading /admin.cgi.

I have had NO problems running this script on my remote webserver which is on a linux box, so it's very frustrating when I can't get it to work locally.

Heather
 
Don't take it out on your poor hair!

Sorry, but I don't have any further suggestions for you except to keep plugging away and hopefully you find the problem.

But don't abuse your hair anymore! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top