Thursday, 26 May 2016

Let's Install and Configure Apache Tomcat on Windows


Hello everybody!

Here is a quick and easy guide for you to install and configure Apache Tomcat on your Windows system. I will try to explain it step by step so that you can follow them easily.

STEP 1

First of all, we need to sure that we have latest versions of jre and jdk installed on our systems. If they are missing on your system, go to http://www.oracle.com/technetwork/java/javase/downloads/index.html to download them. If you want to check my other post about how to check JDK version on your system, you can find it here.


STEP 2

We then need to download Tomcat. For that go to http://tomcat.apache.org/ and go to "Binary Distributions". Under "Core" you will see the zip package. Download and unzip it in your project directory or any folder that you find appropriate. I placed mine under "D://" directory and for ease of use, I renamed it as "tomcat9".


STEP 3

Next step is setting environment variables for Tomcat to be able to find java libraries in our systems. To set the variables go to "Start-> Control Panel-> System->Advanced system settings". You will see a window like below. On that window click "Environment Variables".


In "Environment Variables", under "User Variables" section we need to add (or edit if you are modifying) two variables as you can see down below.



After these changes, now we need to add another variable value to the the system variable "Path". So find and select "Path" variable under "System variables" and click edit button. Then simply add "C:\Program Files\Java\jdk1.8.0_91\bin; " as follows.


STEP 4

After these steps now it is time to do some configurations on Tomcat Server. There are 4 configuration files under the "conf" folder  in your Tomcat folder. So head over where you unzipped your Tomcat in STEP 1 and find this "conf" folder  We are going to deal with:

  • conf/server.xml
  • conf/web.xml
  • conf/content.xml
  • conf/tomcat-users.xml.
You can update these files using a text editor. I am going to use Notepad++. 

Starting with server.xml;

in server.xml the port number stated as 8080 by default. We need to change this port number to something else because this port may already be in use by other servers and applications. To change this port number we can put any number between 1024 to 65535(as the port number is an unsigned 16-bit integer). I will go with 6666.



web.xml;

in the web.xml we are going to change directory listing value from false to true. Simply change "false" value under "listings" to "true". There is warning in here though! I read this on another website.This configuration is not useful in production for security reasons. So better be careful about this.


content.xml;

in content.xml we will enable reloadable by setting its value to "true". So that automatic reloading after code changes will be active. There is again a warning here. This is not useful for production.


tomcat-users.xml;

This step is optional. If you want to add usernames and passwords this is the file you are looking for.


STEP 5

We are almost done. So let's check if everything is working fine. We are going to start and shut down the server. To start the server open your command window(cmd) and set the current directory to Tomcat's home directory and go to /bin. then type "startup.bat".

To shut it down head over to same directory and type "shutdown.bat"

I hope these were all useful for you and you  found what you have been looking for :)

Hope to see you in the next blog post!

Selen

No comments:

Post a Comment