We can run CGI scripts in Tomcat. This post is about using Tomcat to run a CGI script written in PERL.
Software Requirements (used for this post)
- Apache Tomcat 7.0.11
- JDK 1.6 update 21
- Perl 5.12 (ActivePerl-5.12.2.1202)
- Windows XP SP3
Install and Configure
- Download Tomcat. Install or unzip it to some directory.
- Modify <TOMCAT_HOME>\conf\web.xml to uncomment the GCI servlet and its mapping and add a servlet parameter passShellEnvironment and set it to “true”12345678910111213141516171819202122<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><servlet-mapping><servlet-name>cgi</servlet-name><url-pattern>/cgi-bin/*</url-pattern></servlet-mapping>
- Modify <TOMCAT_HOME>\conf\context.xml to add a property on <Context>:123<Context privileged="true">...</Context>
- Create a cgi folder under <TOMCAT_HOME>\webapps\ROOT\WEB-INF\
- Install Perl
- Create a CGI script and place it under <TOMCAT_HOME>\webapps\ROOT\WEB-INF\cgi\1234#!C:\Perl\bin\perl.exe# filename: test1.cgiprint "Content-type: text/html\n\n";print "Hello, world!\n"
- Start Tomcat and access the URL:http://localhost:8080/cgi-bin/test1.cgi