Thursday 22 May 2014

Configuring Tomcat for CGI Perl

Configuring CGI  Perl in Apache Tomcat :

Software Requirement:
  • Apache Tomcat 7.0.11 or above
  • JDK 1.6 or above 
  • Perl 5 or above
  1. Download Tomcat. Install or unzip it to some directory.
  2. Modify <TOMCAT_HOME>/conf/web.xml to uncomment the cgi servlet and its mapping
       uncomment:
 
<servlet>
 <servlet-name>cgi</servlet-name>
 <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
 <init-param>
 <param-name>debug</param-name>
 <param-value>0</param-value>
 </init-param>
 <init-param>
 <param-name>cgiPathPrefix</param-name>
 <param-value>WEB-INF/cgi</param-value>
 </init-param>
 <init-param>
 
add the following:
<init-param>
 <param-name>passShellEnvironment</param-name>
 <param-value>true</param-value>
 </init-param>
 
now the CGI blocks look like:
 
 
<servlet>
 <servlet-name>cgi</servlet-name>
 <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
 <init-param>
 <param-name>debug</param-name>
 <param-value>0</param-value>
 </init-param>
 <init-param>
 <param-name>cgiPathPrefix</param-name>
 <param-value>WEB-INF/cgi</param-value>
 </init-param>
 <init-param>
 <param-name>passShellEnvironment</param-name>
 <param-value>true</param-value>
 </init-param>
 <load-on-startup>5</load-on-startup>
</servlet>
 
3: Modify the servlet-mapping 
 
<servlet-mapping>
 <servlet-name>cgi</servlet-name>
 <url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
 
 
4:Modify <TOMCAT_HOME>\conf\context.xml to add a property on <Context>: 
 
<Context privileged="true">
...
</Context>
 
5.Create a cgi folder under <TOMCAT_HOME>/webapps/ROOT/WEB-INF/
 
mkdir <TOMCAT_HOME>/webapps/ROOT/WEB-INF/cgi
 
6. Create the CGI or Pl file under the same directory 
 
 <TOMCAT_HOME>/webapps/ROOT/WEB-INF/cgi/test.cgi
 
#!C:\Perl\bin\perl.exe
# filename: test1.cgi
print "Content-type: text/html\n\n";
print "Hello, world!\n"
 
7. Restart the Apache server
 
 
  
 
 
 
 
 
 


2 comments:

  1. World's Best Blog...This guy is a champ... Expert in perl...May he live long

    ReplyDelete
  2. Good Work!!

    Your blogs have always helped me, whenever I get struck at any point in configuration.

    Keep sharing your experiences.

    ReplyDelete