Image of Step-by-step guide for installing tomcat on unix

ADVERTISEMENT

Introduction

Here below we provide a step-by-step guide for installing and setting up tomcat in unix environment, for those who are interested in windows machines you can refer to this guide.

1. Prerequisite

Tomcat doesn’t work without java, so before installing tomcat on the machine, you should install a compatible java runtime version and setup JAVA_HOME environment variable. Both java and tomcat versions should be compatible so i recommend to always install the same version for java and tomcat, in this tutorial we use java 8 and tomcat 8.

2. Installation

Following are the steps for setting up tomcat 8 on unix machine:

  1. Download tomcat8 from here into your home directory .i.e. /home/PG tomcat website
  2. Create a new directory called tomcat8 under /usr/local.
  3. Move the downloaded file to /usr/local/tomcat8 and extract it there.
[PG@localhost local]$ mkdir tomcat8
[PG@localhost local]$ cd tomcat8
[PG@localhost tomcat8]$ mv /home/PG/apache-tomcat-8.5.15.tar.gz .
[PG@localhost tomcat8] tar xvzf apache-tomcat-8.5.15.tar.gz

Now set the path of CATALINA_HOME environment variable to /usr/local/tomcat8/apache-tomcat-8.5.15

[PG@localhost]$ export CATALINA_HOME=/usr/local/tomcat8/apache-tomcat-8.5.15
[PG@localhost]$ export PATH=$PATH:$CATALINA_HOME

And here you go, tomcat is installed successfully on your machine.

To start tomcat:

[PG@localhost]$ cd %CATALINA_HOME
[PG@localhost apache-tomcat-8.5.15]$ cd bin
[PG@localhost bin]$ sh startup.sh

To shut down tomcat:

[PG@localhost]$ cd %CATALINA_HOME
[PG@localhost apache-tomcat-8.5.15]$ cd bin
[PG@localhost bin]$ sh shutdown.sh

3. Configuration

To change the default running port of tomcat:

[PG@localhost]$ cd %CATALINA_HOME/conf
[PG@localhost]$ vi server.xml

Then change the port attribute of Connector tag as the following:

<Connector port="9095" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

Here, we set tomcat to run on port 9095 , a restart is required for the change to take effect.

Check if tomcat is up

In order to make sure that tomcat is started up correctly on the configured port, just run :9095 url on any browser and if you get the following screen then tomcat is up and ready to serve requests.\

tomcat website

Alternatively, you can check if there exist a running tomcat process through executing the following command:

[PG@localhost local]$ ps -ef | grep tomcat

4. Tomcat Logging

Tomcat log files can be found under $CATALINA_HOME/logs, there are 2 important log files to be checked when investigating applications issues:

  • tomcat8-stderr..log: This file logs all the runtime exceptions which are thrown by the running application.
  • tomcat8-stdout..log: This file displays all the trace and info logs generated by the application.

OR if these files are not found, you can check catalina..log which holds all the exceptions and info logs generated by the application.

Summary

Here below we provide a step-by-step guide for installing and setting up tomcat in unix environment, for those who are interested in windows machines you can refer to this guide.

Next Steps

If you're interested in learning more about the basics of Java, coding, and software development, check out our Coding Essentials Guidebook for Developers, where we cover the essential languages, concepts, and tools that you'll need to become a professional developer.

Thanks and happy coding! We hope you enjoyed this article. If you have any questions or comments, feel free to reach out to jacob@initialcommit.io.