The cart is empty

Apache Tomcat is an open-source web server and servlet container developed by the Apache Software Foundation (ASF). Tomcat implements several Java EE specifications including Java Servlet, JavaServer Pages (JSP), Java EL, and WebSocket, providing a "pure Java" HTTP web server environment for running Java code. In this article, we will look at the steps required to install and perform basic configuration of Apache Tomcat on a Linux server.

Prerequisites

Before installing Apache Tomcat, it's important to ensure that Java Runtime Environment (JRE) or Java Development Kit (JDK) is installed on your system. Tomcat requires Java to run. You can use the java -version command to verify if Java is installed and to obtain the Java version.

Installing Java

  1. Open the terminal and update your system's package list using the command: sudo apt update.
  2. Install JRE or JDK using the command: sudo apt install default-jdk.

Downloading Apache Tomcat

  1. Visit the official Apache Tomcat website (http://tomcat.apache.org/) and download the latest version of Tomcat. Choose the version suitable for your Java version.
  2. Use wget or curl to download the Tomcat tar.gz archive. For example: wget https://apache.osuosl.org/tomcat/tomcat-9/v9.0.41/bin/apache-tomcat-9.0.41.tar.gz.

Installing Apache Tomcat

  1. Extract the downloaded archive to a suitable directory, such as /opt/tomcat. Use the command: sudo tar xzvf apache-tomcat-*tar.gz -C /opt/tomcat --strip-components=1.
  2. Set user and group permissions for the Tomcat directory. For example: sudo chown -R <username>:<group> /opt/tomcat.

Configuring Environment

For easy execution and management of the Tomcat server, it's advisable to set environment variables:

  1. Open the ~/.bashrc or ~/.profile file in your preferred text editor.
  2. Add lines to set the CATALINA_HOME and JAVA_HOME variables. For example:
    export CATALINA_HOME=/opt/tomcat
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
    ​
  3. Save the file and apply changes using the command source ~/.bashrc or source ~/.profile.

 

Starting Apache Tomcat

  1. Navigate to the /opt/tomcat/bin directory.
  2. Start Tomcat using the ./startup.sh script.
  3. Verify that the server is running by opening http://localhost:8080 in a web browser.

Basic Security Configuration

It's important to ensure that your Tomcat server is secure against unauthorized access:

  1. Change the default ports in the server.xml configuration file located in /opt/tomcat/conf.
  2. Modify or delete the users defined in the /opt/tomcat/conf/tomcat-users.xml file and add your own users with appropriate roles.
  3. Secure access to the management and manager applications by restricting access to only trusted IP addresses.

 

You should now have Apache Tomcat installed and basic configuration performed. For deeper configuration and optimization, it's recommended to refer to the official Tomcat documentation and ensure that your server is updated and secured.