Pre-installation Requirements
1. Java
2. Python
Steps
1. Download Latest version of Tomcat (Tomcat 7) from
http://tomcat.apache.org/download-70.cgi
2. After successful installation of Tomcat modify the Web file in the<tomcat_home>\conf\folder (eg:c:\program files\apache software foundation\tomcat 7.0\conf)
Uncomment the CGI servlet and its mapping
<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>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
3. Add an servlet parameter "Passshellenvironment" and set it to "true" (
"Force" the environment variables to be passed)
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
4. Add an servlet parameter "executable"
<init-param>
<param-name>executable</param-name>
<param-value>C:\Python27\python.exe</param-value>
</init-param>
The overall CGI servlet in Web. XML is given below
<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>executable</param-name>
<param-value>C:\Python27\python.exe</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>
5. Modify <tomcat_home>\conf\context.xml to add a property on <context>:
<context privileged= "true" >
...
</Context>
6. Create a folder say "test" in <tomcat_home>\webapps directory. It is the root folder for your application
7. Create a Web-inf folder inside the root folder (test) and create a CGI folder inside Web-inf folder
8. Create a Python CGI script and put in <tomcat_home>\webapps\test\web-inf\cgi\
hello.py
print "content-type:text/html\n\n";
Print "Hello, world!\n"
9. Start the Tomcat server and browse the URL
http://localhost:8080/test/cgi-bin/hello.py
Configure Tomcat 7 to run Python CGI scripts in Windows (Win7 system configuration Tomcat server with Python for CGI programming)