How to Enable CGI Mode in Apache Tomcat

DZone 's Guide to

How to Enable CGI Mode in Apache Tomcat

Having trouble enabling the CGI mode in your Apache Tomcat? Check out this tutorial to learn more!

· Java Zone ·
Free Resource

Hello Coders, I hope you are all doing well.

Today, I had to enable the CGI mode in Tomcat, while facing lots of issue in the same. So, I thought that, after successful deployment, I would write an article in the same simplified steps. Here it is!

  • First, download the Apache Tomcat (choose the version that is compatible with your application; in my case, I am using the latest one).
  • Go to the CATALINA_HOME/conf and modify the following files:
    • web.xml (Here, we will enable the CGI support in Tomcat)
      • To enable CGI support in Tomcat, we have to uncomment servlet and servlet-mapping of CGI servlet in web.xml.
      • After uncommenting the servlet and servlet-mapping of CGI, we have to add one param value in that servlet mapping to execute our CGI.
    • context.xml
      • We have to set the attribute "privileged" to true for Context.
<!-- web.xml -->



<!-- context.xml -->

<Context privileged="true">

  • Go to the CATALINA_HOME/webapps/ROOT/  directory.
    • Check weather WEB-INF  directory is exist or not, if not create the directory  WEB-INF .
    • Create another directory named as cgi under  WEB-INF.
  • Now, your Tomcat is CGI enabled. You can copy any CGI file under this directory, and it will run successfully.
  • Your base URL will be <<request protocol>>>://<<server-ip>>:<<server-port>>/cgi-bin/<<name of cgi>>, in my case i.e. http://localhost:8080/cgi-bin/test.cgi
  • For more understanding, you can look for CGI-howto section in Tomcat

Let me know if you face any issue after this deployment. Happy Coding!

cgi mode, cgi server, java, tomcat, tomcat 7, tomcat 8, tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}