Solved

Apache CGI Question.

Posted on 2001-07-22
12
510 Views
Last Modified: 2013-11-18
Ok, where to begin.  I'm trying to run a .pl file in my /cgi-bin/ dir.  here is the following info that you may need.

**********httpd.conf**********

# 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 command (see below)
#
# If you want to use server side includes, or CGI outside
# ScriptAliased directories, uncomment the following lines.
#
# To use CGI scripts:
#
#AddHandler cgi-script .cgi
#
# To use server-parsed HTML files
#
AddType text/html .shtml
AddHandler server-parsed .shtml


# If the perl module is installed, this will be enabled.
<IfModule mod_perl.c>
  Alias /perl/ /var/www/perl/
  <Location /perl>
    SetHandler perl-script
    PerlHandler Apache::Registry
    Options +ExecCGI
  </Location>
</IfModule>

<Directory "/home/trogden/www.trogden.com/cgi-bin">
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
  </Directory>
***************************************************

************Guestbook.html***********

<form method="get" action="http://www.trogden.com/cgi-bin/mainguest.pl">
<pre><b>


                  Name <input name="name" size=30>
Internet Email address <input name="email" size=30>
                  City <input name="city">
                 State <input name="state">
               Country <input name="country">

</b></pre>
<b> Comments</b><br>
<textarea name="comment" rows=3 cols=70></textarea><br>
<br>
<center><i>Thank you for signing the guestbook.</i><br>
<input type=submit value="Post to Guestbook">
<input type=reset value="Clear Guest Information Above"></form>
<form method="get" action="http://www.trogden.com/cgi-bin/mainguest2.pl">
<input type=submit value="View Guestbook">
</center>

</html>

*************************************
************Mainguest.pl*************

#!/usr/bin/perl

print "content-type: text/html\n\n";
print "<title>Tommy's  Guestbook</title>\n";
print '<body bgcolor="#ffffff">';
print "<center>Tommy Trogden's Guestbook</center>\n";
print '<center><img src="book.gif"></center>';
print "<center>Posting Guestbook Information</center>\n";

#get the input
$in=$ENV{'QUERY_STRING'};

# split the name-value pairs
@pairs = split(/&/, $in);

foreach $pair (@pairs)
{
   ($name, $value) = split(/=/, $pair);
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}

open (guest, ">>guestbook");
print guest"<font color=red> The Following information was posted to the guestbook
</font>\n";
print guest "<font color=blue font size=+1>Name $FORM{'name'}\n";
print guest "Email-$FORM{'email'}\n";
print guest "City- $FORM{'city'}\n";
print guest "State- $FORM{'state'}\n";
print guest "Country- $FORM{'country'}\n";
print guest "Comment --------------------------------------------\n";
print guest "$FORM{'comment'}</font></font>\n";

close (guest);

print "<hr>";
print "<center><b>$FORM{'name'}</b>your guestbook entry was added!!  ";
print 'have a great day! Bye!<img align=middle src="hand.gif">';
print '<form type="link"
action="http://www.trogden.com/cgi-bin/mainguest2.pl"><input type=submit value="View
Guestbook"></form></center>';

********Mainguest2.pl**************

#!/usr/bin/perl

print "content-type: text/html\n\n";
print "<title>Contents of guestbook</title>\n";
print '<body bgcolor="#ffffff">';
print "<center><h2>Tommy Trogden's Custom Guestbook</h2></center>";

print "<center>Current Guestbook Information</center>\n";
print "<br>";

open(readin,'guestbook');
print "<pre>";

while ( <readin> ) {

if ($_ =~ /the following information was posted to the guestbook/) {
print "<hr size=2>";
print "<B>$_</b>";
}
else {print;}
}
close(readin);
print "<hr size=+2>";
print "<center>";
print "<b>You have reached the end of my guestbook!!\n";
print "Have a great day! Bye!</b>";
print "</pre>";

*************************************

ok, I can run this at the command line in the cgi-bin dir by typing ./mainguest.pl and I get the correct info.  When I try and run it from my webpage I get a 404 file not found and an error message in the log saying:
script not found or unable to stat: /home/trogden/www.trogden.com/cgi-binmainguest.pl
why is it missing the / in the above line ?? There should be a / between cgi-bin and mainguest.pl  Am I missing something ??


ttrogden
0
Comment
Question by:ttrogden
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6308957
Add in <IfModule mod_alias.c>
  ScriptAlias /cgi-bin/ "/home/trogden/www.trogden.com/cgi-bin/"
0
 
LVL 1

Author Comment

by:ttrogden
ID: 6308993
where do I add this at ??  It looks like it goes in the httpd.conf, but where at ??

tommyt
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6309009
yes in httpd.conf (then re-read my comment)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:ttrogden
ID: 6309316
ok, when I read your comment it sounded like you wanted me to add in:

<IfModule mod_alias.c>
 ScriptAlias /cgi-bin/ "/home/trogden/www.trogden.com/cgi-bin/"

Brain fart !!


so this is what I added :
# If the perl module is installed, this will be enabled.

<IfModule mod_perl.c>
  Alias /perl/ /var/www/perl/
  ScriptAlias /cgi-bin/ "/home/trogden/www.trogden.com/cgi-bin/"
<Location /perl>
    SetHandler perl-script
    PerlHandler Apache::Registry
    Options +ExecCGI
  </Location>
</IfModule>


It still doesn't work.  I'm getting the same error messages in the error_log:
script not found or unable to stat: /home/trogden/www.trogden.com/cgi-binmainguest.pl

  Any idea's ??  I did change the .pl to .cgi and also changed .html to .shtml and still nothing, so I've changed everything back.

tommyt
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6309686
hmm, first you postet the right change:

<IfModule mod_alias.c>
ScriptAlias /cgi-bin/ "/home/trogden/www.trogden.com/cgi-bin/"
# ...
</IfModule>

But then you posted that you have written the ScriptAlias in the:  <IfModule mod_perl.c> Scope

Sounds like a mistake, somehow ...
0
 
LVL 1

Author Comment

by:ttrogden
ID: 6309769
I have a newborn and he's zapped out my common sense, anyway, i did put that in the wrong place.  I removed it from the perl area and couldn't find the mod_alias.c area so I just created it.  I ran the test and I still get the same error in my logs and still get the 404 error.  any more ideas ??

tommyt
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6309821
> any more ideas ?
ask the newborn, it's a brand new brain :-))
anayway, hope you restarted apache after changeing the config. Are there other unusual messages in you logs?
Could you please post the exact message (from browser *and* the corresponding from the error log).
0
 
LVL 1

Author Comment

by:ttrogden
ID: 6309865
I've changed the .pl to .cgi's - for no other reason than thats what it was when I first created them. (I changed the html to reflect it)


***************************************************
Here is what is in the address field
http://www.trogden.com/cgi-bin/mainguest.cgi?name=tommyt&email=&city=&state=&country=&comment=

and the error message on the browser is file not found.

***********Error_log*************************
[Mon Jul 23 16:13:49 2001] [error] [client 65.68.229.185] script not found or unable to stat: /home/trogden/www.trogden.com/cgi-binmainguest.cgi
[Mon Jul 23 16:13:51 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/feather.gif
[Mon Jul 23 16:13:54 2001] [error] [client 65.68.229.185] script not found or unable to stat: /home/trogden/www.trogden.com/cgi-binmainguest.cgi
[Mon Jul 23 16:13:56 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/book.gif
[Mon Jul 23 16:13:56 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/feather.gif
[Mon Jul 23 16:13:57 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/book.gif
[Mon Jul 23 16:13:57 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/feather.gif
[Mon Jul 23 16:13:59 2001] [error] [client 65.68.229.185] script not found or unable to stat: /home/trogden/www.trogden.com/cgi-binmainguest.cgi
[Mon Jul 23 16:14:10 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/book.gif



It's missing the *.gif's which is no big deal, what is interesting is the "/cgi-binmainguest.cgi" why no / between the bin and mainguest.cgi ??


**************************************

Anything else ??
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 6309881
strange to me ...
last idea: change
   <Directory "/home/trogden/www.trogden.com/cgi-bin">
to
   <Directory "/home/trogden/www.trogden.com/cgi-bin/">
0
 
LVL 1

Author Comment

by:ttrogden
ID: 6309910
I've changed the .pl to .cgi's - for no other reason than thats what it was when I first created them. (I changed the html to reflect it)


***************************************************
Here is what is in the address field
http://www.trogden.com/cgi-bin/mainguest.cgi?name=tommyt&email=&city=&state=&country=&comment=

and the error message on the browser is file not found.

***********Error_log*************************
[Mon Jul 23 16:13:49 2001] [error] [client 65.68.229.185] script not found or unable to stat: /home/trogden/www.trogden.com/cgi-binmainguest.cgi
[Mon Jul 23 16:13:51 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/feather.gif
[Mon Jul 23 16:13:54 2001] [error] [client 65.68.229.185] script not found or unable to stat: /home/trogden/www.trogden.com/cgi-binmainguest.cgi
[Mon Jul 23 16:13:56 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/book.gif
[Mon Jul 23 16:13:56 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/feather.gif
[Mon Jul 23 16:13:57 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/book.gif
[Mon Jul 23 16:13:57 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/feather.gif
[Mon Jul 23 16:13:59 2001] [error] [client 65.68.229.185] script not found or unable to stat: /home/trogden/www.trogden.com/cgi-binmainguest.cgi
[Mon Jul 23 16:14:10 2001] [error] [client 65.68.229.185] File does not exist: /home/trogden/www.trogden.com/htdocs/book.gif



It's missing the *.gif's which is no big deal, what is interesting is the "/cgi-binmainguest.cgi" why no / between the bin and mainguest.cgi ??


**************************************

Anything else ??
0
 
LVL 1

Author Comment

by:ttrogden
ID: 6309970
that little slash fixed it all.

Thanks

Tommyt
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6311358
hmm, that's still strange to me, 'cause my apache works without slash in the Directory scope but with slash in the ScriptAlias directive.
Which apache version are you using?
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question