You are here
Home > How To > How To Install Tomcat 8 On Windows

How To Install Tomcat 8 On Windows

Tomcat

As of September 2017, Tomcat 9 is at the alpha stage, not a stable release. So We are going to install Tomcat 8.5.11.

Step 1: Download and Install Tomcat 8

  • Goto http://tomcat.apache.org ⇒ Under Downloads ⇒ Under “Tomcat 8” ⇒ Binary Distributions ⇒ Core ⇒ Click on “ZIP” package (e.g. you will get “apache-tomcat-8.5.20.zip”, about 9 MB).
  • Create your server directory into day drive, say “c:\servers” , “d:\servers” or “e:\servers”. UNZIP the downloaded file into your server directory. Tomcat will be unzipped into directory e.g., “e:\servers\apache-tomcat-8.0.20”.
  • For ease of use, we shall shorten and rename this directory to “e:\servers\tomcat8”.

Note : e:\servers\tomcat8 is tomcat install home directory

Step 2: Create an Environment Variable JAVA_HOME

You need to create an environment variable called “JAVA_HOME” and set it to your JDK installed directory.

  • First, find your JDK installed directory. The default is “c:\Program Files\Java\jdk1.8.0_{xx}”. memorize of your JDK installed directory or copy paste into somewhere.
  • To set the environment variable JAVA_HOME in Windows 7/8/10: Start “Control Panel” ⇒ System and Security (Optional) ⇒ System ⇒ Advanced system settings ⇒ Switch to “Advanced” tab ⇒ Environment Variables ⇒ System Variables ⇒ “New” ⇒ In “Variable Name”, enter “JAVA_HOME” ⇒ In “Variable Value”, enter your JDK installed directory as copied or noted in previous step.

STEP 3: Configure Tomcat Server

The Tomcat configuration files are located in the “conf” sub-directory of your Tomcat installed directory, e.g. “e:\servers\tomcat8\conf”. There are 4 configuration XML files:

  1. server.xml
  2. web.xml
  3. context.xml
  4. tomcat-users.xml

Step 3(1): “conf\server.xml” – Set the TCP Port Number

  • Use a any programming text editor (e.g., NotePad++, TextPad, Sublime, Atom) to open the configuration file “server.xml”, under the “conf” sub-directory of Tomcat installed directory.
  • The default TCP port number configured in Tomcat is 8080, you may choose any number between 1024 and 65535, which is not used by an existing application. We shall choose 2017 in this article. (For a production server, you should use default port number 80, which is pre-assigned to HTTP server.)
  • Locate the following lines (around Line 69) that define the HTTP connector, and change port=”8080″ to port=”2017″.
<!– A “Connector” represents an endpoint by which requests are received and responses are returned. –>
<Connector port=”2017″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ />

Step 3(b): “conf\web.xml” – Enabling Directory Listing

  • Again, use a programming text editor to open the configuration file “web.xml”, under the “conf” sub-directory of Tomcat installed directory.
  • We shall enable directory listing by changing “listings” from “false” to “true” for the “default” servlet. This is handy for a test system, but due to security reasons not for a production system.
  • Locate the following lines (around Line 103) that define the “default” servlet, and change the “listings” from “false” to “true”.
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

Step 3(c): “conf\context.xml” – Enabling Automatic Reload

  • We shall add the attribute reloadable=”true” to the element to enable automatic reload after code changes. Again, this is handy for test system but not for production, due to the overhead of detecting changes.
  • Locate the “Context” start element (around Line 19), and change it to given below.
<Context reloadable=”true>
……
……
</Context>

Step 3(d): (Optional) “conf\tomcat-users.xml”

  • Enable the Tomcat’s manager by adding the below code:
<tomcat-users>
<role rolename=”manager-gui”/>
<user username=”manager” password=”XXXXXXXX” roles=”manager-gui”/>
</tomcat-users>

STEP 4: Start Tomcat Server

  • The Tomcat’s executable programs and scripts are kept in the “bin” sub-directory of the Tomcat installed directory, e.g., “e:\servers\tomcat8\bin”
  • Launch a CMD shell. Set the current directory to “\bin” e.g. “e:\servers\tomcat8\bin
  • Run “startup.bat”
// Change the current directory to Tomcat’s “bin”
// Assume that Tomcat is installed in “e:\servers\tomcat8\bin”
e: // Change the current drive
cd \servers\tomcat8\bin // Change Directory to YOUR Tomcat’s “bin” directory

// Start Tomcat Server
startup.bat

Step 5: Shutdown Server
You can shutdown the tomcat server by either:

  • Press Ctrl-C on the Tomcat console; OR
  • Run “\bin\shutdown.bat” script.
// Change the current directory to Tomcat’s “bin”
e: // Change the current drive
cd \servers\tomcat8\bin // Change Directory to YOUR Tomcat’s “bin” directory

// Shutdown the server
shutdown.bat

Jay Prakash Kumar
If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Facebook or Twitter. Jay Prakash is a founder of Professional Hacker, Technical Writer, Software Developer, Security Analyst and Technology Enthusiast with a keen eye on the Cyber-world and other technology-related developments.
https://professionalhacker.in/

One thought on “How To Install Tomcat 8 On Windows

Comments are closed.

Top