This shows how to configure Apache Tomcat 8 for CGI.
Software Environment
These are the items we used for this post.
- Windows 7 Professional SP1
- Any web browser
- Apache Tomcat 8.0.14
- ActivePerl 5.16.3.1604 (Windows x86)
- Java 1.7 (1.7.0_67 – Windows x86)
Install Java SE Development Kit 7
The first thing we need to do is install Java in Windows 7. Here are the steps on how to perform the installation.
First, download Java SE Development Kit 7 from Oracle.
Second, install Java SE Developer Kit 7.
Finally, verify the installation.
Install ActivePerl For CGI Script
First, download ActivePerl from www.activestate.com.
Then, install ActivePerl.
Next, append the c:\<PERL HOME>\bin to %PATH%. We can do the last step either on the command line to invoke Tomcat start.bat or System Properties -> Advanced tab -> Environment Variables -> PATH.
Finally, verify the installation.
Download and Extract Apache Tomcat 8
First, download Apache Tomcat from www.apache.org. Then, choose “zip” from Core on the Binary Distributions section.
Next, extract the archive to any directory
Configure Apache Tomcat to enable CGI
First, modify <SOMEWHERE>/apache-tomcat-8.0.14/conf/web.xml by uncommenting the whole cgi <servlet> tag and adding passShellEnvironment = true init-param.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <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> |
Then, modify <SOMEWHERE>/apache-tomcat-8.0.14/conf/context.xml by adding a privileged attribute and setting its value to true.
1 2 3 | <Context privileged="true"> ... </Context> |
Next, create a “cgi” directory under <SOMEWHERE>/apache-tomcat-8.0.14/webapps/ROOT/WEB-INF. Fourth, create a .cgi script under <SOMEWHERE>/apache-tomcat-8.0.14/webapps/ROOT/WEB-INF/cgi
1 2 3 | # filename: test1.cgi print "Content-type: text/html\n\n"; print "Hello, Turreta! How are you today?\n"; |
Then, start Tomcat 8 up.
Finally, access http://localhost:8080/cgi-bin/test1.cgi
Tomcat 7
To configure Tomcat 7 for CGI, read the following post.