GeeCON Prague 2014*
The moose likes Tomcat and the fly likes setting Tomcat 6 up to run CGI scripts (Perl) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "setting Tomcat 6 up to run CGI scripts (Perl)" Watch "setting Tomcat 6 up to run CGI scripts (Perl)" New topic
Author

setting Tomcat 6 up to run CGI scripts (Perl)

Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
We are trying to enable our Tomcat 6 server to run a CGI script in Perl. We went to tomcat6/conf/web.xml and uncommented the portions of XML that defined the CGI servlet, setting cgiPathPrefix to WEB-INF/cgi, and its mapping, setting the URL pattern to cgi/* . We created a WEB-INF/cgi directory and unpacked scripts into it. We downloaded servlets-cgi.renametojar from a Tomcat 5 distribution, placed it in tomcat6/lib/, and renamed it to servlets-cgi.jar. (There was no such file in the Tomcat 6 distribution.) We restarted Tomcat after each step and pointed our browser to the CGI script URL. The browser loads the script as text, but does not run it. The text tells us that we haven't configured Tomcat properly to run CGI scripts. The first line in the CGI script is

#!/usr/bin/perl

and we have confirmed that we have a working Perl installation at that location.

Any suggestions?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is it a privileged context?

Also, I'm not sure about the bang-script notation, as per http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html

It wasn't obvious to me that it'd be honored.
Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
In /etc/tomcat6/context.xml, I see the line,

<Context privileged="true">

So I believe the answer to your question is, yes.
Charles Owen
Ranch Hand

Joined: Aug 31, 2009
Posts: 61
If you are running Tomcat6 then you do not need to add this cgi jar. That's only if you are using Tomcat 5.5 or below.

I don't think your problem is in the perl installation. I think it's how you are configuring the CGI.
I've gotten CGI to work in Tomcat6. However, in my case I am turning on the CGI within my application web.xml, rather than in the global web.xml.

This is my directory structure.
/webapps/perlexample/WEB-INF/cgi/test.pl

Then I created a perlexample.xml in my $CATALINA_BASE/conf/Catalina/localhost directory.



Then it works. I am thinking you are missing this application xml in your $CATALINA_BASE/conf/Catalina/localhost directory.
Charles Owen
Ranch Hand

Joined: Aug 31, 2009
Posts: 61
And this is my very simple PERL script.

Jitmer Jijo
Greenhorn

Joined: Oct 17, 2010
Posts: 6
if you are getting java.security.xception make sure to do the following

In the directory $CATALINA_HOME\conf\ set the root element as <Context privileged="true"> in the context.xml file

i.e add privileged="true" attribute in the <Context > root element
 
GeeCON Prague 2014
 
subject: setting Tomcat 6 up to run CGI scripts (Perl)