| |||||||||||
| |||||||||||
Running CGI scripts in Apache Tomcat
CGI scripts are usually run under an httpd web server, but if you've only got a few CGIs and a lot of .jsp-s and servlets, you may want to run them under Tomcat instead. It can be done, but there are some configuration things to do first! SAMPLE CGI SCRIPT Here's a sample cgi script that you might want to install on your Tomcat server: #!/usr/bin/perl print "Content-type: text/html\n\n"; $now = localtime(); print "<h1>It is $now</h1>"; The file should be: * In a directory called WEB-INF/cgi in the webapp * have an extension .cgi * be set to be executable (chmod a+x xxxxxx) If you want to vary the location and extension, you can do so by altering the text configuration quoted below. CONFIGURING TOMCAT TO SUPPORT CGI Although CGI support is shipped with the standard Tomcat load, the vital information that you'll need is commented out in the web.xml file and you need to uncomment the following to add in the support: <servlet> <servlet-name>cgi</servlet-name> <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>6</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> and also you need to map appropriate URLs on to that support: <servlet-mapping> <servlet-name>cgi</servlet-name> <url-pattern>*.cgi</url-pattern> </servlet-mapping> There's one further change to make - the CGI API is provided in a .jar file that you need to rename in the /usr/local/tomcat/server/lib (or similarly named) directory: mv servlets-cgi.renametojar servlets-cgi.jar See also Deploying applications under httpd and Tomcat Please note that articles in this section of our
web site were current and correct to the best of our ability when published,
but by the nature of our business may go out of date quite quickly. The
quoting of a price, contract term or any other information in this area of
our website is NOT an offer to supply now on those terms - please check
back via our main web site
Related Material
Web Application Deployment - Tomcat - Configuring Web Applications Web Application Deployment - Tomcat -Sourcing, Installing and Initial Testing Web and Intranet - Executable Content resource index - Java Solutions centre home page You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum. At Well House Consultants, we provide training courses on subjects such as Ruby, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site. |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||