Atlantic.Net Blog

How to Install Apache Tomcat 10 on Rocky Linux 8

Hitesh Jethva
by Atlantic.Net (273 posts) under Dedicated Server Hosting, Tutorials
0 Comments

Apache Tomcat is an open-source web server used for deploying Java-based web applications. It is platform-independent and allows you to runs the JavaServer (JSP), JavaServlet, and Java Expression languages. Apache Tomcat enables a webserver to handle dynamic Java-based web content using the HTTP protocol.

In this post, we will explain how to install Apache Tomcat 10 on Rocky Linux 8.

Prerequisites

  • A fresh Rocky Linux 8 server on the Atlantic.Net Cloud Platform
  • A valid domain name pointed to your server IP
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Rocky Linux 8 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your Rocky Linux 8 server, run the following command to update your base system with the latest available packages.

dnf update -y

Step 2 – Install Java

Apache Tomcat is a Java-based application, so Java must be installed on your server. If not installed, you can install it using the following command:

dnf install java-11-openjdk -y

After installing Java, verify the Java version with the following command:

java -version

Sample output:

openjdk version "11.0.12" 2021-07-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)

Step 3 – Download Apache Tomcat 10

Before starting, you will need to add a dedicated user for Tomcat. You can add it using the following command:

useradd -r -d /opt/tomcat/ -s /bin/false -c "Tomcat User" tomcat

Next, download the latest version of Apache Tomcat 10 using the following command:

wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.10/bin/apache-tomcat-10.0.10.tar.gz

After downloading Apache Tomcat, create a directory for Tomcat and extract the downloaded file inside the /opt/tomcat directory:

mkdir /opt/tomcat
tar xzf apache-tomcat-10.0.10.tar.gz -C /opt/tomcat --strip-components=1

Next, change the ownership of /opt/tomcat directory to tomcat:

chown -R tomcat: /opt/tomcat/

Step 4 – Configure Tomcat Admin User

Next, you will need to create an admin user for managing Manager and Host Manager. You can do it by editing the /opt/tomcat/conf/tomcat-users.xml file:

nano /opt/tomcat/conf/tomcat-users.xml

Add the following lines just above the last line:

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

Save and close the file when you are finished.

Step 5 – Configure Tomcat for Remote Host

By default, Tomcat can be accessed only from the localhost, so you will need to configure Tomcat to access it from the remote host.

To access the Manager from the remote host, 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" />

Save and close the file when you are finished.

To access the Host Manager from the remote host, 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 finished.

Step 6 – Create a Systemd Unit File for Apache Tomcat

Next, it is recommended that you create a systemd unit file to manage the Tomcat service. You can create it with the following command:

nano /etc/systemd/system/tomcat.service

Add the following lines:

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

[Service]
Type=forking
User=tomcat
Group=tomcat

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

ExecStart=/opt/tomcat/bin/catalina.sh start
ExecStop=/opt/tomcat/bin/catalina.sh stop

RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target

Save and close the file, then reload the systemd daemon with the following command:

systemctl daemon-reload

Next, start the Tomcat service and enable it to start at system reboot:

systemctl start tomcat
systemctl enable tomcat

You can verify the status of the Tomcat service with the following command:

systemctl status tomcat

Sample output:

● tomcat.service - Apache Tomcat Server
   Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-08-08 09:35:36 UTC; 20s ago
  Process: 16830 ExecStart=/opt/tomcat/bin/catalina.sh start (code=exited, status=0/SUCCESS)
 Main PID: 16841 (java)
    Tasks: 24 (limit: 23695)
   Memory: 99.6M
   CGroup: /system.slice/tomcat.service
           └─16841 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.ju>

Aug 08 09:35:36 RockyLinux8 systemd[1]: Starting Apache Tomcat Server...
Aug 08 09:35:36 RockyLinux8 systemd[1]: Started Apache Tomcat Server.

Step 7 – Access Apache Tomcat Web UI

At this point, Apache Tomcat is started and listening on port 8080. You can check it with the following command:

ss -antpl | grep 8080

Sample output:

LISTEN 0      100                     *:8080            *:*    users:(("java",pid=16841,fd=43))                                                                                                    

You can now access Tomcat using the URL http://your-server-ip:8080. You should see the following screen:
Access Tomcat
To access the Manager App, click on the Manager App button. You will be asked to provide an admin user and password as shown below:
Tomcat Login Page
Provide your admin username and password and click on the Sign in button. You should see the following screen:
Tomcat Manager Page
To access the Host Manager App, click on the Host Manager link. You should see the following screen:
Tomcat Host Manager Page

Conclusion

Congratulations! You have successfully installed Apache Tomcat 10 on Rocky Linux 8. You can now deploy your Java application easily with Apache Tomcat on your Atlantic.Net dedicated server hosting account.

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources