?
Solved

Apache CGI Question.

Posted on 2001-07-22
12
Medium Priority
?
537 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
  • 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
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

850 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