In this tutorial, we’ll guide you through the process of how to install Apache Tomcat on Rocky Linux. Tomcat is a popular open-source Java Servlet container, developed by the Apache Software Foundation. It’s widely used for deploying and running Java-based web applications.
Before we begin, make sure you have:
- A Rocky Linux system up and running.
- A user with sudo privileges.
How to Install Apache Tomcat on Rocky Linux
Update Your System
First, update your system packages to their latest versions:
sudo dnf update -y
Install Java Development Kit (JDK)
Tomcat requires Java Development Kit (JDK) to run. Install OpenJDK 11 using the following command:
sudo dnf install java-11-openjdk-devel -y
Verify the Java installation by checking its version:
Create Tomcat User and Group on Rocky Linux
Create a new user and group for running the Tomcat service. This ensures better security and isolation:
sudo groupadd tomcat sudo useradd -M -s /sbin/nologin -g tomcat -d /opt/tomcat tomcat
Download and Install Apache Tomcat on Rocky Linux
Download the latest version of Tomcat from the official website. At the time of writing, the latest version is 9.0.x. Adjust the version number accordingly:
Example: wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.74/bin/apache-tomcat-9.0.74.tar.gz
Extract the downloaded archive and move it to the
sudo tar xf apache-tomcat-9.0.x.tar.gz sudo mv apache-tomcat-9.0.x /opt/tomcat
Change the ownership of the Tomcat directory to the
tomcat user and group:
sudo chown -R tomcat:tomcat /opt/tomcat
Configure Systemd Service on Rocky Linux
Create a new systemd service file for Tomcat:
sudo nano /etc/systemd/system/tomcat.service
Add the following content to the file:
[Unit] Description=Apache Tomcat Web Application Container After=network.target [Service] Type=forking User=tomcat Group=tomcat Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk" Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid" Environment="CATALINA_HOME=/opt/tomcat" Environment="CATALINA_BASE=/opt/tomcat" ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh Restart=on-failure [Install] WantedBy=multi-user.target
Save the file and exit the editor.
Start and Enable Tomcat on Rocky Linux
Reload the systemd daemon to register the new service:
sudo systemctl daemon-reload
Start the Tomcat service:
sudo systemctl start tomcat
Enable the Tomcat service to start on boot:
sudo systemctl enable tomcat
Check the status of the Tomcat service:
sudo systemctl status tomcat
Configure Firewall on Rocky Linux
If you have a firewall running, allow the default Tomcat port (8080) through the firewall:
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent sudo firewall-cmd --reload
Access Tomcat Web Interface
Now that Tomcat is installed and running, you can access the web interface to manage your Tomcat server. Open your web browser and navigate to the following URL:
your_server_ip with the actual IP address of your Rocky Linux server. You should see the Apache Tomcat welcome page.
Secure the Tomcat Manager and Host Manager Applications (Optional)
By default, the Tomcat Manager and Host Manager applications are not secured. To secure them, you need to create a user with a role that has access to these applications.
sudo nano /opt/tomcat/conf/tomcat-users.xml
Add the following lines inside the
<role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="your_username" password="your_password" roles="manager-gui,admin-gui"/>
your_password with your desired username and password.
Save the file and exit the editor. Restart Tomcat for the changes to take effect:
sudo systemctl restart tomcat
Now, you can access the Tomcat Manager and Host Manager applications by clicking on their respective links on the Tomcat welcome page and entering your username and password when prompted.
You have successfully installed and configured Apache Tomcat on your Rocky Linux server. You can now deploy and manage Java-based web applications using the Tomcat Manager and Host Manager applications. Remember to keep your Tomcat installation up-to-date with the latest security patches and updates. Learn How to Set up NTP Server on Rocky Linux and How to Install Bacula Backup Server on Rocky Linux