Configure Tomcat 7 to run Python CGI scripts in Windows (Win7 system configuration Tomcat server with Python for CGI programming)

Source: Internet
Author: User
Tags tomcat server

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.