In this tutorial, we will show you how to install Apache Tomcat on AlmaLinux 8. For those of you who didn’t know, Apache Tomcat (formerly known as Jakarta Tomcat) is an open-source web server developed by Apache to provide a Java HTTP server that allows you to easily run Java files. In most of the production, Tomcat is used in conjunction with Apache HTTP Server where Apache HTTP Server attends static content like HTML, images, etc., and forwards the requests for dynamic content to Tomcat.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Apache Tomcat for system administration on AlmaLinux 8. You can follow the same instructions for Rocky Linux.
- A server running one of the following operating systems: AlmaLinux 8, CentOS, or Rocky Linux.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install Apache Tomcat on AlmaLinux 8
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf update sudo dnf install epel-release
Step 2. Installing Java.
Here we will install the OpenJDK version that is available in the official repo. You can go for an older version as well if you want. Choose and install the one as per your choice:
- Install Java 11:
sudo dnf install java-11-openjdk
- Install Java 8:
sudo dnf install java-1.8.0-openjdk
Once the Java installation is complete, run the below command to verify the Java version:
Step 3. Create Tomcat Service Account.
Let’s create a group and user that will have access to Tomcat only and cannot be used for other purposes such as login to the system to install or delete anything:
sudo groupadd tomcat sudo mkdir /opt/tomcat sudo useradd -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
Step 4. Installing Apache Tomcat on AlmaLinux 8.
Now we download the Apache Tomcat installer from the official page and save it in your working directory:
wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.8/bin/apache-tomcat-10.0.8.tar.gz sudo tar -zxvf apache-tomcat-*.tar.gz -C /opt/tomcat --strip-components=1
Next, set the proper file permissions:
sudo chown -R tomcat: /opt/tomcat sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh'
Step 5. Create Apache Tomcat Systemd Service.
We need to create a startup script to manage Tomcat as
systemd a service. Let’s create a
sudo nano /etc/systemd/system/tomcat.service
Add the following line:
[Unit] Description=Tomcat webs servlet container After=network.target [Service] Type=forking User=tomcat Group=tomcat Environment="JAVA_HOME=/usr/lib/jvm/jre" Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom" Environment="CATALINA_BASE=/opt/tomcat" Environment="CATALINA_HOME=/opt/tomcat" Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid" Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC" ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh [Install] WantedBy=multi-user.target
Save and close, also start and enable Apache Tomcat service:
sudo systemctl daemon-reload sudo systemctl start tomcat sudo systemctl enable --now tomcat
Step 6. Configure Firewall.
Allow Apache Tomcat service port in Linux firewall:
sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp sudo firewall-cmd --reload
Step 7. Configure Apache Tomcat Application Manager.
By default, you will only be able to access the Tomcat default page. To access admin and other sections such as Server Status, App Manager, and Host Manager, you need to configure the user account for admin and administrators. We need to configure Managers Apps according to our requirements:
sudo nano /opt/tomcat/conf/tomcat-users.xml
Copy and paste the following lines:
<role rolename="admin"/> <role rolename="admin-gui"/> <role rolename="manager"/> <role rolename="manager-gui"/> <user username="idroot" password="strongpasswd" roles="admin,admin-gui,manager,manager-gui"/>
Next, edit the following files to let us access them from other machines:
sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml
Find and comment following lines of code:
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
Just add <!– at the beginning and –> in the end, after that, this will look like something this:
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
Finally, restart Apache Tomcat 10 service:
sudo systemctl restart tomcat
Step 8. Accessing Apache Tomcat Web Interface.
Once successfully installed, open your web browser and go to the following address:
http://your-server-ip-address:8080 If you see a similar page as on the picture below, that means Tomcat was properly installed.
Congratulations! You have successfully installed Apache Tomcat. Thanks for using this tutorial for installing the Apache Tomcat on your AlmaLinux 8 system. For additional help or useful information, we recommend you check the official Apache Tomcat website.