Link to home
Start Free TrialLog in
Avatar of ramble
rambleFlag for United States of America

asked on

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:

https://www.experts-exchange.com/questions/21071252/CGI-scripting-not-working.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
Avatar of ramazanyich
ramazanyich
Flag of Belgium image

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
Avatar of ramble

ASKER

Ok, I did that, (and restarted Apache), but it didn't seem to make any difference.

Could you check error.log of your Apache and send error lines ?
Avatar of ramble

ASKER

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)"
something wrong in your gc.cgi.
Could you send source code?
Avatar of ramble

ASKER

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
Avatar of ramble

ASKER

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:
https://www.experts-exchange.com/questions/20868761/Premature-end-of-script-headers-error.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...?
Avatar of ramble

ASKER

Well, I tried the "--" and that didn't work.
Avatar of ramble

ASKER

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...
could you try to execute your script from UNIX shell ? Maybe it is a perl compilation problem ?
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
Avatar of brozzis
brozzis


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


Avatar of ramble

ASKER

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.
Avatar of ramble

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of ramazanyich
ramazanyich
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually you should have following lines:
 AddType text/html .pl
AddOutputFilter INCLUDES .pl
 Options +Includes
Avatar of ramble

ASKER

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...)

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

Avatar of ramble

ASKER

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!
Avatar of ramble

ASKER

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.