Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Running Perl CGI scripts under Apache Tomcat

Posted by admin (Graham Ellis), 6 September 2005
Q I'm using Tomcat but I've got thie script in Perl. Do I have to run Apache httpd as well?

A Common wisdom is that you use Apache httpd for general web serving, including PHP and Perl scripts through CGI.  And you use Apache Tomcat for Javabased applications.  Common wisdom goes on to say that if you require both Perl and Java applications, you run both httpd and Tomcat.

But .. if you've only got a little CGI traffic, you can serve CGI scripts through Tomcat.  How?

1. Alter Tomcat's conf/web.xml file

a) There's a CGIServlet that's commented out; remove the comments so that the live file contains.

Code:
<servlet>
       <servlet-name>cgi</servlet-name>
       <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
       <init-param>
         <param-name>debug</param-name>
         <param-value>6</param-value>
       </init-param>
       <init-param>
         <param-name>cgiPathPrefix</param-name>
         <param-value>WEB-INF/cgi</param-value>
       </init-param>
        <load-on-startup>5</load-on-startup>
   </servlet>



b) Associate URLs cgi-bin with the CGI Servlet.

Code:
<servlet-mapping>
       <servlet-name>cgi</servlet-name>
       <url-pattern>/cgi-bin/*</url-pattern>
   </servlet-mapping>



2. Rename the CGI jars supplied with (but disabled) in Tomcat

Code:
cd /usr/local/tomcat/server/lib
mv servlets-ssi.renametojar servlets-ssi.jar
mv servlets-cgi.renametojar servlets-cgi.jar


3. In your webapps/xxxx/WEB-INF folder, add a new directory called cgi and place your CGI script in there.   Example content:

Code:
#!/usr/bin/perl
print ("Content-type: text/html\n\n");
$now = localtime();
print <<"STUFF";
<html>
<head><title>Wow!</title></head>
<body bgcolor=green text=white>
This is going to look naff at $now
</body>
</html>
STUFF


And mark this file executable

Then restart Tomcat to ensure it's picked up the new, global, web.xml file.

Note - this example is written with exact details for Tomcat 5.5.9, Apache 2.0.54 and Fedora Core 3 Linus.

Posted by admin (Graham Ellis), 9 January 2006
on 09/06/05 at 19:22:52, Graham Ellis wrote:
Q I'm using Tomcat but I've got thie script in Perl. Do I have to run Apache httpd as well?

Note - this example is written with exact details for Tomcat 5.5.9, Apache 2.0.54 and Fedora Core 3 Linux.


Err ... the answer I gave was that you DON'T necessarily need httpd, so the httpd version 2.0.54 that I mentioned is totally irrelevant   ... sorry about that!



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.


Visitor Ranking 5.0 (5=excellent, 1=poor)

edit your own (not yet published) comments

Average page ranking - 5.0

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho