Solved

Apache CGI Question.

Posted on 2001-07-22
12
500 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Virtual host in apache 31 90
MVC and Angular 2 104
How do the JavaScript &&  !== operators work together? 3 56
ignore other .htaccess 2 45
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.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 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