Solved

Apache CGI Question.

Posted on 2001-07-22
12
490 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now