Solved

Apache CGI Question.

Posted on 2001-07-22
12
519 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

726 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