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
- Open the terminal and update your system's package list using the command:
sudo apt update
. - Install JRE or JDK using the command:
sudo apt install default-jdk
.
Downloading Apache Tomcat
- 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.
- 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
- 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
. - 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:
- Open the
~/.bashrc
or~/.profile
file in your preferred text editor. - Add lines to set the
CATALINA_HOME
andJAVA_HOME
variables. For example:export CATALINA_HOME=/opt/tomcat export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
- Save the file and apply changes using the command
source ~/.bashrc
orsource ~/.profile
.
Starting Apache Tomcat
- Navigate to the
/opt/tomcat/bin
directory. - Start Tomcat using the
./startup.sh
script. - 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:
- Change the default ports in the
server.xml
configuration file located in/opt/tomcat/conf
. - Modify or delete the users defined in the
/opt/tomcat/conf/tomcat-users.xml
file and add your own users with appropriate roles. - 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.