| # Apache Tomcat 7 Version 7.0.82, Sep 29 2017 |

Links Docs Home FAQ User Comments User Guide 1) Introduction 2) Setup 3) First webapp 4) Deployer 5) Manager 6) Realms and AAA 7) Security Manager 8) JNDI Resources 9) JDBC DataSources 10) Classloading 11) JSPs 12) SSL/TLS 13) SSI 14) CGI 15) Proxy Support 16) MBeans Descriptors 17) Default Servlet 18) Clustering 19) Load Balancer 20) Connectors 21) Monitoring and Management 22) Logging 23) APR/Native 24) Virtual Hosting 25) Advanced IO 26) Additional Components 27) Mavenized 28) Security Considerations 29) Windows Service 30) Windows Authentication 31) Tomcat's JDBC Pool 32) WebSocket Reference Release Notes Configuration Tomcat Javadocs Servlet Javadocs JSP 2.2 Javadocs EL 2.2 Javadocs WebSocket 1.1 Javadocs JK 1.2 Documentation Apache Tomcat Development Building Changelog Status Developers Architecture Functional Specs. Tribes | # CGI How To
Table of Contents
Introduction Installation Configuration
Introduction
The CGI (Common Gateway Interface) defines a way for a web server to interact with external content-generating programs, which are often referred to as CGI programs or CGI scripts. Within Tomcat, CGI support can be added when you are using Tomcat as your HTTP server and require CGI support. Typically this is done during development when you don't want to run a web server like Apache httpd. Tomcat's CGI support is largely compatible with Apache httpd's, but there are some limitations (e.g., only one cgi-bin directory). CGI support is implemented using the servlet class `org.apache.catalina.servlets.CGIServlet`. Traditionally, this servlet is mapped to the URL pattern "/cgi-bin/*". By default CGI support is disabled in Tomcat.
Installation
CAUTION - CGI scripts are used to execute programs external to the Tomcat JVM. If you are using the Java SecurityManager this will bypass your security policy configuration in `catalina.policy.` To enable CGI support: There are commented-out sample servlet and servlet-mapping elements for CGI servlet in the default `$CATALINA_BASE/conf/web.xml` file. To enable CGI support in your web application, copy that servlet and servlet-mapping declarations into `WEB-INF/web.xml` file of your web application. Uncommenting the servlet and servlet-mapping in `$CATALINA_BASE/conf/web.xml` file enables CGI for all installed web applications at once. Set `privileged="true"` on the Context element for your web application. Only Contexts which are marked as privileged are allowed to use the CGI servlet. Note that modifying the global `$CATALINA_BASE/conf/context.xml` file affects all web applications. See Context documentation for details.
Configuration
There are several servlet init parameters which can be used to configure the behaviour of the CGI servlet. cgiPathPrefix - The CGI search path will start at the web application root directory + File.separator + this prefix. By default there is no value, which results in the web application root directory being used as the search path. The recommended value is `WEB-INF/cgi` enableCmdLineArguments - Are command line parameters generated from the query string as per section 4.4 of 3875 RFC? The default is `true`. environment-variable- - An environment to be set for the execution environment of the CGI script. The name of variable is taken from the parameter name. To configure an environment variable named FOO, configure a parameter named environment-variable-FOO. The parameter value is used as the environment variable value. The default is no environment variables. executable - The name of the executable to be used to run the script. You may explicitly set this parameter to be an empty string if your script is itself executable (e.g. an exe file). Default is `perl`. executable-arg-1, executable-arg-2, and so on - additional arguments for the executable. These precede the CGI script name. By default there are no additional arguments. envHttpHeaders - A regular expression used to select the HTTP headers passed to the CGI process as environment variables. Note that headers are converted to upper case before matching and that the entire header name must match the pattern. Default is `ACCEPT[-0-9A-Z]*|CACHE-CONTROL|COOKIE|HOST|IF-[-0-9A-Z]*|REFERER|USER-AGENT` parameterEncoding - Name of the parameter encoding to be used with the CGI servlet. Default is `System.getProperty("file.encoding","UTF-8")`. That is the system default encoding, or UTF-8 if that system property is not available. passShellEnvironment - Should the shell environment variables from Tomcat process (if any) be passed to the CGI script? Default is `false`. stderrTimeout - The time (in milliseconds) to wait for the reading of stderr to complete before terminating the CGI process. Default is `2000`. The name and path of the CGI script to search for in the CGI search path depends on how the Servlet has been mapped. If the pathInfo is `null`, the servletPath will be used. If the pathInfo is not `null` then the servletPath is appended to the CGI search path and the pathInfo is used. The search will start with the first path segment and expand one path segment at a time until no path segments are left (resulting in a 404) or a matching script is found in the CGI search path. Any remaining path segments will be passed to the CGI executable in the PATH_INFO environment variable.
Comments
Notice: This comments section collects your suggestions on improving documentation for Apache Tomcat. If you have trouble and need help, read Find Help page and ask your question on the tomcat-users mailing list. Do not ask such questions here. This is not a Q&A section. The Apache Comments System is explained here. Comments may be removed by our moderators if they are either implemented or considered invalid/off-topic.
Copyright © 1999-2017, Apache Software Foundation