0% found this document useful (0 votes)
151 views9 pages

How To Install Apache Tomcat Server On Ubuntu 22.04

The document provides instructions for installing Apache Tomcat server on Ubuntu 22.04. It describes downloading and extracting Tomcat, changing ownership, creating a systemd service file, configuring security with a username and password, and enabling remote access. Key steps include installing Java, extracting Tomcat to /opt/tomcat, configuring the systemd service, adding an admin user, and removing remote access restrictions from context files.

Uploaded by

Favour Godspower
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views9 pages

How To Install Apache Tomcat Server On Ubuntu 22.04

The document provides instructions for installing Apache Tomcat server on Ubuntu 22.04. It describes downloading and extracting Tomcat, changing ownership, creating a systemd service file, configuring security with a username and password, and enabling remote access. Key steps include installing Java, extracting Tomcat to /opt/tomcat, configuring the systemd service, adding an admin user, and removing remote access restrictions from context files.

Uploaded by

Favour Godspower
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

How to Install Apache Tomcat Server on Ubuntu 22.

04
The Apache Software Foundation developed and maintains the open
source web server for Java programs known as Apache Tomcat. Its
purpose is to host and distribute Java servlets, which are server-side Java
code snippets responsible for managing HTTP responses from client
Java applications.
Further, Apache Tomcat functions as a web server, providing critical
web server processing capabilities for the relevant servlets, rather than
an entire application server with features such as load balancing and data
persistence. Additionally, it supports the init(), service(), and
destroy() methods as part of the Java servlet lifecycle.

Advantages of Apache Tomcat


Tomcat Server is the ideal option for the reasons listed below.
Open Source Application
Released under a general public license is an open source application.
Hence, it enables anyone to utilize its core files for developing both
personal and commercial applications, as it is downloaded and installed
on your computer for free.
Flexible
Its customization feature allows for building applications flexibly,
offering users the ability to execute apps differently to meet their unique
requirements. Users are free to make changes to the application
according to their preferences, and it still works efficiently, producing
top notch results.
Additional Security
Apache Tomcat provides users with advanced security features.
Organizations frequently use firewalls to safeguard their data, and
Tomcat can be installed to accomplish this goal.
Lightweight
In order to function effectively, enterprise level application development
requires lightweight applications. Apache Tomcat’s lightweight nature
enables users to rapidly obtain data processing capacity, making content
development a straightforward process.
Stability
Tomcat has undergone several significant modifications that have
greatly improved its stability. Even if one server fails, the remaining
servers continue to function, ensuring that your application stays online
at all times.
Well Documented
Furthermore, Apache Tomcat is very extensively documented for those
interested in learning how to build Tomcat applications. Many online
tutorials cover various topics such as setup instructions, startup options,
platform support, and server configuration on the Tomcat platform.
Features of Apache Tomcat
Scalability
Well, Tomcat is simply scaled up or down to adapt to changes in
application demand. It is therefore a versatile choice for businesses
whose needs change.
Clustering
To ensure high availability and scalability, Tomcat supports clustering,
which enables several servers to cooperate. This is especially helpful for
large scale applications that need load balancing and high availability.
Embeddable
Tomcat offers flexibility in its use because it may be integrated into
other programs or frameworks. This makes it possible for developers to
make solutions that are unique to their needs.
Extensible
Tomcat may be highly customized with the help of add ons and plugins.
Programmers update the server’s functionalities as needed as a result.
Management
Besides, Tomcat offers a web based administration panel that enables
administrators to keep an eye on and control the server and its
applications. Due to this managing and configuring Tomcat deployments
is simple.
Servlet and JSP Support
Apache Tomcat provides full support for Java Servlet API and
JavaServer Pages(JSP). Java is consequently a tool that programmers
may use to build dynamic, data driven web applications.
Cross Platform
Tomcat is compatible with Windows, Linux, and macOS. Developers
that operate across several platforms are drawn to it by its flexibility.
Resource pooling
The connection pooling functionality of Tomcat permits the sharing of
many database connections among separate requests. As a result,
database-dependent applications might operate more efficiently.
Sessional management
The connection pooling function of Tomcat permits the sharing of many
database connections among separate requests. As a result, applications
that rely on databases might work more efficiently.
Monitoring and logging
Developers follow the performance of their applications and identify
problems as they occur due to Tomcat’s robust monitoring and logging
capabilities.
How to Install Apache Tomcat Server on Ubuntu 22.04
In this section, we explain how to install the Apache Tomcat server on
Ubuntu.
Prerequisites
An Ubuntu 22.04 server is installed on your system.
A root user or a user with sudo privileges.
Install Apache Tomcat
It is a good idea to create a dedicated user to run the Apache Tomcat
server. Create a new user called tomcat using the following command.
useradd -m -U -d /opt/tomcat -s /bin/false tomcat

Next, download the latest version of Apache Tomcat from its official
website using the following command.
wget
https://archive.apache.org/dist/tomcat/tomcat-10/v10.0.
20/bin/apache-tomcat-10.0.20.tar.gz

Once the Apache Tomcat is downloaded, extract the downloaded file


with the following command.
tar -xvf apache-tomcat-10.0.20.tar.gz

Next, move the content of the extracted directory to the Apache Tomcat
home directory.
mv apache-tomcat-10.0.20/* /opt/tomcat

Then, change ownership of the Tomcat directory to tomcat.


chown -R tomcat: /opt/tomcat

Next, set the execution permission on Tomcat binary file.


sh -c 'chmod +x /opt/tomcat/bin/*.sh'

Once you are done, please proceed to the next step.


Also Read
How to Install Apache Tomcat Server on CentOS Stream 9 Tutorial
Create a Systemd Service File for Apache Tomcat
It is also recommended to create a systemd service file to manage the
Apache Tomcat service. Create it with the following command.
nano /etc/systemd/system/tomcat.service

Add the following configurations.


[Unit]
Description=Apache Tomcat
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/opt/jdk-17.0.9
Environment=CATALINA_PID=/opt/tomcat/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment=CATALINA_TMPDIR=/opt/tomcat/temp
Environment="CATALINA_OPTS=-Xms64M -Xmx1024M -server -
XX:+UseParallelGC"

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

ExecReload=/bin/kill $MAINPID
RemainAfterExit=yes

# Security
User=tomcat
Group=tomcat
PrivateTmp=yes
AmbientCapabilities=CAP_NET_BIND_SERVICE
NoNewPrivileges=true
CacheDirectory=tomcat10mm
CacheDirectoryMode=750
ReadWritePaths=/opt/tomcat/conf/
ReadWritePaths=/opt/tomcat/webapps/
ReadWritePaths=/opt/tomcat/logs/
[Install]
WantedBy=multi-user.target

Save and close the file then reload the systemd daemon to apply the
changes.
systemctl daemon-reload

Next, start the Apache Tomcat service and enable it to start at system
reboot with the following command.
systemctl enable --now tomcat

Also check the status of the Apache Tomcat service with the following
command.
systemctl status tomcat

This shows you the active status of Apache Tomcat.


check tomcat status
To check the Apache Tomcat listening ports, run the following
command.
ss -antpl | grep -i java

You should see Tomcat ports on the following screen.


Configure Apache Tomcat
At this point, the Apache Tomcat is installed and running on your server.
Now, you need to add an admin user and password to secure the Apache
Tomcat. You can do it by editing tomcat-users.xml file.
nano /opt/tomcat/conf/tomcat-users.xml

Add the following lines above the line </tomcat-users>:


<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="admin" password="securepassword"
roles="admin-gui,manager-gui"/>

Save and close the file when you are finished.


Enable Apache Tomcat Remote Access
By default, Apache Tomcat is accessed only from the localhost. To
access the Apache Tomcat from the remote machine, you need to edit
the context.xml file and remove the access restriction.
To enable remote access for Tomcat Manager, edit the context.xml
file.
nano /opt/tomcat/webapps/manager/META-INF/context.xml

Remove the following lines:


<Valve
className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"
/>

To enable remote access for Tomcat Host Manager, edit the


context.xml file.
nano
/opt/tomcat/webapps/host-manager/META-INF/context.xml

Remove the following lines.


<Valve
className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1"
/>

Save and close the file when you are done. Then, restart the Tomcat
service to implement the changes.
systemctl restart tomcat
Access Apache Tomcat
Now, Apache Tomcat is installed on your server. Access it using the
URL http://your-server-ip:8080 on your web browser. You
should see the Tomcat dashboard on the following screen.

You might also like