Solved

CGI scripting (perl) not working

Posted on 2004-08-31
20
435 Views
Last Modified: 2013-11-18
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
Comment
Question by:ramble
[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
20 Comments
 
LVL 19

Expert Comment

by:ramazanyich
ID: 11944014
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
 

Author Comment

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

0
 
LVL 19

Expert Comment

by:ramazanyich
ID: 11944742
Could you check error.log of your Apache and send error lines ?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ramble
ID: 11944920
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
 
LVL 19

Expert Comment

by:ramazanyich
ID: 11944985
something wrong in your gc.cgi.
Could you send source code?
0
 

Author Comment

by:ramble
ID: 11945014
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
 

Author Comment

by:ramble
ID: 11945048
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
 

Author Comment

by:ramble
ID: 11945191
Well, I tried the "--" and that didn't work.
0
 

Author Comment

by:ramble
ID: 11945409
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
 
LVL 19

Expert Comment

by:ramazanyich
ID: 11947633
could you try to execute your script from UNIX shell ? Maybe it is a perl compilation problem ?
0
 
LVL 9

Expert Comment

by:ronan_40060
ID: 11949932
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
 
LVL 2

Expert Comment

by:brozzis
ID: 11950812

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
 

Author Comment

by:ramble
ID: 11952417
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
 

Author Comment

by:ramble
ID: 11952507
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
 
LVL 19

Accepted Solution

by:
ramazanyich earned 500 total points
ID: 11952785
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
 
LVL 19

Expert Comment

by:ramazanyich
ID: 11952803
Actually you should have following lines:
 AddType text/html .pl
AddOutputFilter INCLUDES .pl
 Options +Includes
0
 

Author Comment

by:ramble
ID: 11955774
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
 
LVL 19

Expert Comment

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

0
 

Author Comment

by:ramble
ID: 11958267
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
 

Author Comment

by:ramble
ID: 11958286
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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Suggested Solutions

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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

739 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