Apache Tomcat Download and Installation

To install Apache Tomcat:

  1. (Optional) It is recommended to update the system with the latest security patch.

  2. Install OpenJDK.

For Java 8:

›_ Console

# dnf install java-1.8.0-openjdk java-1.8.0-openjdk-devel

For Java 11:

›_ Console

# dnf -y install java-11-openjdk java-11-openjdk-devel

  1. Download Tomcat 10.

›_ Console

# wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.27/bin/apache-tomcat-

10.0.27.tar.gz

  1. Create a directory.

›_ Console

# mkdir -p /opt/tomcat

  1. Extract the archived file to /opt/tomcat.

›_ Console

# tar -xvf apache-tomcat-10.0.27.tar.gz -C /opt/tomcat --strip-components=1

  1. Change the ownership of the /opt/directory to tomcat user.

›_ Console

# chown -R tomcat:tomcat /opt/tomcat

  1. Set executable permissions to scripts.

›_ Console

# chmod +x /opt/tomcat/bin/*.sh

  1. Create Apache Tomcat Systemd file /etc/systemd/system/tomcat.service to manage the Tomcat service through systemctl and add the lines below.

›_ Console

[Unit]

Description=Apache Tomcat Web Application Container

Wants=network.target

After=network.target


[Service]

Type=forking


Environment=JAVA_HOME=/usr/lib/jvm/jre


Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid

Environment=CATALINA_HOME=/opt/tomcat

Environment='CATALINA_OPTS=-Xms512M -Xmx1G -Djava.net.preferIPv4Stack=true' Environment='JAVA_OPTS=-Djava.awt.headless=true'


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

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

SuccessExitStatus=143


User=tomcat

Group=tomcat

UMask=0007

RestartSec=10

Restart=always


[Install]

WantedBy=multi-user.target

Change the values according to your system configuration.


tmpoen_b0e1.jpg

/etc/systemd/system/tomcat.service file output

  1. Reload the daemon.

›_ Console

# systemctl daemon-reload

  1. Start and enable the Tomcat service.

›_ Console

# systemctl start tomcat

# systemctl enable tomcat

  1. Confirm that the Tomcat service is running.

›_ Console

# systemctl status tomcat.service

tmp9k79pnwx.jpg

Tomcat Service Status

  1. Open http://<apache_tomcat_-server-ip>:8080 in any web browser and verify if Apache Tomcat page is visible.

tmpjqk0n92t.jpg

Browser Output over page 8080