Apache Tomcat | Free HTTP Web Server for Java Web Apps
Open Source HTTP Web Server Environment For Java Web Apps

Tomcat Web Server Solution Stack

HTTP Web Server Environment For Java Web Apps

Execute Java servlets and render web pages that include Java server page coding. Apache Tomcat software powers large-scale, mission-critical web applications.

Apache Tomcat is an open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language, and Java WebSocket technologies. It is one of the most widely used application and web server. Tomcat server is simple to use and has a robust ecosystem of add-ons. Apache Tomcat Software can be used as a standalone product with its own internal Web server as well as with other Web servers such as Apache, Netscape Enterprise Server, Microsoft Personal Web Server, and Microsoft Internet Information Server.

It turns out to have an easy to use web interface. Tomcat is a very simple, efficient, and easily installable tool and the configuration process is very basic. The fact that it is easy to configure makes it a very helpful tool to test developments in a simple, easy and fast way. It has integrations with other environments development such as Eclipse, which allows to code web pages in a much easier way.

System Requirements

  • Ubuntu 18.04 Operating system.
  • Non-root user with sudo privileges configured on your server.

Features

Apache Tomcat software provides almost all web server features including Tread pool, Connection pool, Https, Mutual and info Source. It offers a set of very rich API, which is powerfully incorporated with practically main IDE including Eclipse, and IntelliJ. Following are some stand out features of Tomcat:

  • It’s Incredibly Lightweight.
  • It’s Open-Source.
  • Load balancing.
  • It can manage large applications.
  • Servlet 3.0 and JSP 2.2 specifications.
  • JSP parsing.
  • Thanks to its lightweight nature and a suite of extensive, built-in customization options, Tomcat is quite flexible.
  • Tomcat is an extremely stable because it runs independently of your Apache installation.
  • It Offers An Extra Level Of Security.
  • Tomcat is mature as it has existed for nearly 20 years.
  • Tomcat has a variety of good documentation available, including a wide range of online tutorials that can be viewed or downloaded.
  • It’s the most widely used Java application server.
  • It’s geared towards Java-based content.
  • A high-availability feature has been added to facilitate the scheduling of system upgrades without affecting the live environment.

Installation

Follow these steps to Install Apache Tomcat 9 on Ubuntu 18.04:

  • First of all, update the package index using following command:
sudo apt update
  • Install the OpenJDK package by running following command:
sudo apt install default-jdk
  • After that, create Tomcat User.
sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat
  • Now, download the Tomcat archive in the /tmp directory using the following wget command:
wget http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz -P /tmp
  • Extract the Tomcat archive and move it to the /opt/tomcat directory using following command:
sudo tar xf /tmp/apache-tomcat-9*.tar.gz -C /opt/tomcat
  • After that, create the symbolic link called ‘latest’ that points to the Tomcat installation directory:
sudo ln -s /opt/tomcat/apache-tomcat-9.0.27 /opt/tomcat/latest
  • Use following command to change the directory ownership:
sudo chown -RH tomcat: /opt/tomcat/latest
  • Then set executable flag for the scripts inside bin directory.
sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'
  • To run Tomcat as a service you need to create a new unit file.
  • Create a file named tomcat.service in the /etc/systemd/system/:
sudo nano /etc/systemd/system/tomcat.service
  • Paste the following configuration into newly created file:
[Unit]
Description=Tomcat 9 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target
  • Note*: Modify the value of JAVA_HOME according to the path to your Java installation.
  • Save and close the file and restart using following command:
sudo systemctl daemon-reload
  • Start Tomcat Service using following command
sudo systemctl start tomcat
  • Check status with the following command:
sudo systemctl status tomcat
  • Now If there are no errors, enable the Tomcat service.
sudo systemctl enable tomcat
  • After that, adjust the Firewall.
sudo ufw allow 8080/tcp
  • Then configure Tomcat Web Management Interface.
sudo nano /opt/tomcat/latest/conf/tomcat-users.xml
  • Edit the following two files to allow access to the web interface from anywhere.
  • Comment out the lines under tag.
  • For the Host Manager app, open the following file:
sudo nano /opt/tomcat/latest/webapps/manager/META-INF/context.xml
  • For the Manager app, open the following file:
sudo nano /opt/tomcat/latest/webapps/host-manager/META-INF/context.xml
  • After that, comment out the code as follows:

<Context antiResourceLocking="false" privileged="true" >