[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

CGI scripting (perl) not working

I've decided I needed a walk-through.  There must be something that I'm just not understanding.  I've read numerous postings on EE like this one:

http://www.experts-exchange.com/Web/Web_Servers/Apache/Q_21071252.html

But it doesn't want to cooperate with me.

I download a script from:
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Access_Counters/Graphical/

Specifically, it's called: Ascad Graphical Counter

And I can't get it to work.

I Added Script Aliasing to httpd.conf:

ScriptAlias /cgi-bin/ "/home/httpd/vhosts/a_domain.com/httpdocs/"

<Directory "/home/httpd/vhosts/a_domain.com/httpdocs/">
    AllowOverride Options
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

AddHandler cgi-script .cgi .pl

In the "a_domain.com" index.html, I have:
<!--#exec cgi="gc.cgi"-->

reguardelss, I can't even run it doing this:
www.a_domain.com/gc.cgi   (give me internal server error)

If I change the name from gc.cgi to gc.pl, I don't get any errors, but it doesn't appear to run correctly either.

Do I even need .htaccess in the directory that the CGI is in (which is in the root of this particular domain).  I went ahead and put it there anyway.

fyi: I installed this same script on another Fedora/apache box, and it works just fine.  Unfortunately, I don't have admin rights to that server, so I can't view it's setup to determine the differences...

Thanks_ramble
0
ramble
Asked:
ramble
1 Solution
 
ramazanyichCommented:
You should add Includes to your Options directive to allow execution of Server SIde Includes (such as <!--#exec).
So change you Options line :
Options ExecCGI Includes
0
 
rambleAuthor Commented:
Ok, I did that, (and restarted Apache), but it didn't seem to make any difference.

0
 
ramazanyichCommented:
Could you check error.log of your Apache and send error lines ?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
rambleAuthor Commented:
error_log

[Tue Aug 31 11:36:50 2004] [error] [client 129.17.73.109] Premature end of script headers: gc.cgi
[Tue Aug 31 11:41:35 2004] [error] [client 129.17.73.109] Premature end of script headers: gc.cgi
[Tue Aug 31 11:41:40 2004] [error] [client 129.17.73.109] Premature end of script headers: gc.cgi

access_log

129.17.73.109 - - [31/Aug/2004:11:41:35 -0500] "GET /gc.cgi HTTP/1.1" 500 1264 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
129.17.73.109 - - [31/Aug/2004:11:41:40 -0500] "GET /gc.cgi HTTP/1.1" 500 1264 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
129.17.73.109 - - [31/Aug/2004:11:48:56 -0500] "GET /gc.cgi HTTP/1.1" 500 1264 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
0
 
ramazanyichCommented:
something wrong in your gc.cgi.
Could you send source code?
0
 
rambleAuthor Commented:
gc.cgi is the same "counter" code from the link above.

I download a script from:
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Access_Counters/Graphical/

Specifically, it's called: Ascad Graphical Counter
0
 
rambleAuthor Commented:
It has a couple of parameters to change in the code..-location of perl, location (with respect to the gc.cgi script) of the digits (gif files)...but that's it really.  The instructions for installing this script are pretty straight forward...and as I mentioned earlier, I have successfully installed it on a different server.

I was reading:
http://www.experts-exchange.com/Web/Web_Servers/Apache/Q_20868761.html

And thought I'd try the '--' "temporary solution".  I'm running apache 2.0.48 - so it could be part of the behavior they mentioned...?
0
 
rambleAuthor Commented:
Well, I tried the "--" and that didn't work.
0
 
rambleAuthor Commented:
Ok...let me see if I at least "understand" what is going on:

1. ScriptAlias /cgi-bin/ "/home/httpd/vhosts/a_domain.com/httpdocs/"

This, I assume, is an aliase to /cgi-bin/ whenever a client browses to a_domain.com/cgi-bin...it points to the files in /a_domain.com/httpdocs/.

I'm assuming this is a global setting, and effects all virtual domains on the server.

So, what happens if you do this:

ScriptAlias /cgi-bin/ "/home/httpd/vhosts/a_domain.com/httpdocs/"
ScriptAlias /cgi-bin/ "/home/httpd/vhosts/b_domain.com/httpdocs/"

Is that legal?

Second...

<Directory "/home/httpd/vhosts/a_domain.com/httpdocs/">
    AllowOverride Options
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

I'm assuming the above is an "exception" of the scriptalias.  That the directory specified above is allowed to execute CGI scripts.

I don't know what the difference in:
Options ExecCGI and
Options +ExecCGI

I'm not even sure if .htaccess is required for any of this to work (usually found in the directory that your wanting to access)

AddHandler cgi-script .cgi .pl

I'm assuming that the line above simply activates these "extensions" (cgi and pl) for execution.

Feel free to correct me, or add anything...
0
 
ramazanyichCommented:
could you try to execute your script from UNIX shell ? Maybe it is a perl compilation problem ?
0
 
ronan_40060Commented:
hello ramble
try
AddHandler cgi-script .cgi    instead of AddHandler cgi-script .cgi .pl
 and save and restart your apache and execute ur cgi scripts
let us know
ronan
0
 
brozzisCommented:

my guess is (given that previous aswers didn't solve your problem):
the script has not the correct privileges to be run by the owner of the process apache (httpd)
alternatively the cgi-bin directory has not "rx" privileges...

su - apache -c "/full/absolute/path/to/script.pl"

could be the right way to check this


0
 
rambleAuthor Commented:
ramazanyich: Yes, no problems executing it from a shell.

ronan 40060: I did - didn't seem to make a difference.  Infact, the .pl still seem to run.  (I'll explain below)

brozzis: I've chmod -R 777 <the_cgi_directory>

So, it doesn't appear to be a permissions problem.
0
 
rambleAuthor Commented:
Ok, I'm trying to make this a bit easier to debug.  I created a quick test cgi script called "test.cgi".   It contains:

#!/usr/bin/perl

use CGI;                            
$co = new CGI;                        
print $co->header,                    
$co->start_html(-title=>'Test CGI execution'),
$co->center($co->h1('CGI execution test!')),
$co->start_form(),
$co->textarea
(
    -name=>'textarea',
    -rows=>10,
    -columns=>60
),
$co->end_form(),
$co->end_html;  

Characteristics of running this:

www.a_domain.com/test.cgi (Internal 500 error)

coping test.cgi to test.pl

www.a_domain.com/test.pl  (runs just fine!)

I also ran: perl -pe 's/\015\012/\n/g' <test.cgi >test2.cgi
to make sure that I don't have any hidden carriage returns...etc.

As another test, I created index.html that contains only:

<HTML>
This is the domain <b>a_domain.com</b>.    
<!--#exec cgi="test.cgi"-->
<BR><BR>
</HTML>

Then I changed test.cgi to test.pl

It did't run, only "This is the domain a_domain.com" came up in the browser.

It acted like it completly ignored the #exec cgi directive.
0
 
ramazanyichCommented:
Could you check that your config contains all necessary config lines that described in that URL:
http://httpd.apache.org/docs-2.0/mod/mod_include.html 
Check "Enabling Server-Side Includes" part
0
 
ramazanyichCommented:
Actually you should have following lines:
 AddType text/html .pl
AddOutputFilter INCLUDES .pl
 Options +Includes
0
 
rambleAuthor Commented:
Remeber the index.html I posted above, as a test...well, I found something interesting, which may prove to 'lick' this annoyance once in for all...

index.html

<HTML>
This is the domain <b>a_domain.com</b>.    
<!--#exec cgi="test.cgi"-->
<BR><BR>
</HTML>

On the server that "works", it traslates the:
<!--#exec cgi="test.cgi"-->

into:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"><head><title>Test CGI execution</title>
</head><body><center><h1>CGI execution test!</h1></center><form method="post" action="/index.html" enctype="application/x-www-form-urlencoded">
<textarea name="textarea" rows="10" cols="60"></textarea><div></div></form></body></html>

While the server that I'm having problems with simply displays:
<!--#exec cgi="test.cgi"-->

(This was verified through the browser choosing "view source code")

So the server doesn't seem to have SSI turned on.

ramazanyich: looks like your suggestion is taking the right path, I'm going to go read a little on the suggestions you posted above.

why do you want .pl?  why wouldn't that be .cgi?  the .cgi extension is what I want to work...(referring to the AddType text/html .pl   etc...)

0
 
ramazanyichCommented:
replace .pl by .cgi in my suggestion:
AddType text/html .cgi

0
 
rambleAuthor Commented:
Ok, so here's what I found out: (for future people following this thread)

SSI works in *.shtml by default. To made SSI work in *.html you should add:
AddHandler server-parsed .html in /etc/httpd/conf/httpd.conf for all sites

That's All!  Now it works. (restart apache ofcourse)

Now, fyi, If you only want one particular site to parse through .html files, in /home/httpd/vhosts/<domain-name>/conf/vhost.conf and run the following:
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=<domain_name> for the only site. (See ADVANCED FEATURES MANUAL chapter 6).  
(This is for a site running PLESK - Which mine is)

Ulitmately, ramazanyich link:
http://httpd.apache.org/docs-2.0/mod/mod_include.html 

Lead me to the correct solution.  Thanks!
0
 
rambleAuthor Commented:
I really didn't get a chance to add the lines you suggested:

AddType text/html .cgi
AddOutputFilter INCLUDES .cgi
Options +Includes

I need to read up on these as well, if you have any "other" good links, let me know.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now