Discover how to install Apache Tomcat on Rocky Linux 9 with our detailed guide. Empower your web application development and deployment process by harnessing the capabilities of this powerful and versatile servlet container. Follow our step-by-step instructions for seamless integration on your Linux environment. #centlinux #linux #apachetomcat
Apache Tomcat (called “Tomcat” for short) is a free and open-source implementation of the Jakarta Servlet, Jakarta Expression Language, and WebSocket technologies. It provides a “pure Java” HTTP web server environment in which Java code can also run. Thus it’s a Java web application server, although not a full JEE application server.
Tomcat is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation, released under the Apache License 2.0 license.
Apache Tomcat is a widely used open-source servlet container that is used for deploying and running Java-based web applications. It functions as a lightweight web server that serves Java Servlets and JavaServer Pages (JSP) over the HTTP protocol. Here are some common use cases for Apache Tomcat:
Overall, Apache Tomcat is a versatile and widely used servlet container that provides developers with a lightweight, scalable, and efficient platform for deploying Java-based web applications. Its ease of use, robustness, and compatibility with Java standards make it a popular choice for web application development and deployment in both development and production environments.
Apache and Tomcat are often compared because they are both used in the realm of web server technology, but they serve different purposes and have different functionalities:
In summary, Apache and Tomcat serve different roles in web server technology. Apache HTTP Server is primarily used as a general-purpose web server for serving static content, while Apache Tomcat is specifically designed for executing Java web applications. In many cases, Apache and Tomcat are used together, with Apache serving as the front-end web server and handling static content, while Tomcat serves dynamic content generated by Java web applications.
Recommended Online Training: Apache Tomcat Server from Beginners to Advanced
We are using a minimal installed Rocky Linux 9 virtual machine with following specifications.
Read Also: How to install Apache Tomcat on CentOS 7
By using a ssh client, login to your Linux server as root user.
Set a FQDN (Fully Qualified Domain Name) for your Rocky Linux server.
# hostnamectl set-hostname tomcat-01.centlinux.com
Refresh your yum cache by using dnf command.
# dnf makecache Rocky Linux 9 - BaseOS 280 kB/s | 1.7 MB 00:06 Rocky Linux 9 - AppStream 653 kB/s | 6.4 MB 00:09 Rocky Linux 9 - Extras 3.0 kB/s | 7.0 kB 00:02 Metadata cache created.
Execute following command to upgrade software packages in your Linux operating system.
# dnf update -y
Sometimes, the above command also upgrades your Linux Kernel.
In such situation, you should reboot your Linux operating system with newly installed Kernel.
# reboot
After reboot, check the Linux Kernel and operating system versions.
# cat /etc/rocky-release Rocky Linux release 9.1 (Blue Onyx) # uname -r 5.14.0-162.6.1.el9_1.0.1.x86_64
By using dnf command, install software packages that are required to download and install Apache Tomcat software.
# dnf install -y wget tar gzip
Apache Tomcat 10.0.x requires Java 8 or later JRE (Java Runtime Environment).
Therefore, you can install OpenJDK 11 (an open source implementation of Java platform) on Linux machine.
# dnf install -y java-11-openjdk
After installation, check the version of your active Java runtime environment.
# java --version openjdk 11.0.17 2022-10-18 LTS OpenJDK Runtime Environment (Red_Hat-11.0.17.0.8-2.el9_0) (build 11.0.17+8-LTS) OpenJDK 64-Bit Server VM (Red_Hat-11.0.17.0.8-2.el9_0) (build 11.0.17+8-LTS, mixed mode, sharing)
Create a Linux user to own Tomcat software and processes.
# useradd -r -d /opt/tomcat/ -s /sbin/nologin -c "Tomcat User" tomcat
Apache Tomcat website provides the latest version of Java application server for various platforms.
You can use wget command to download Tomcat software directly from Linux CLI.
# cd /tmp # wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.27/bin/apache-tomcat-10.0.27.tar.gz --2022-12-13 08:48:03-- https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.27/bin/apache-tomcat-10.0.27.tar.gz Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644 Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 11984522 (11M) [application/x-gzip] Saving to: ‘apache-tomcat-10.0.27.tar.gz’ apache-tomcat-10.0. 100%[===================>] 11.43M 1.14MB/s in 10s 2022-12-13 08:48:13 (1.14 MB/s) - ‘apache-tomcat-10.0.27.tar.gz’ saved [11984522/11984522]
Create a directory and extract downloaded tarball therein.
# mkdir /opt/tomcat # tar xf apache-tomcat-10.0.27.tar.gz -C /opt/tomcat --strip-components=1
Grant ownership of /opt/tomcat directory to tomcat user.
# chown -R tomcat:tomcat /opt/tomcat/
You need to create one or more admin users to manage your Tomcat server via Application Manager.
Edit tomcat-users.xml file by using vim text editor.
# vi /opt/tomcat/conf/tomcat-users.xml
Add following lines just before </tomcat-users> tag.
<role rolename="admin-gui"/> <role rolename="manager-gui"/> <user username="admin" password="admin" roles="admin-gui,manager-gui"/> <user username="ahmer" password="123" roles="admin-gui,manager-gui"/>
By default Application Manager is allowed to be accessed from localhost only.
Therefore, you must edit the following file to make your application manager accessible from other machines within the same network.
# vi /opt/tomcat/webapps/manager/META-INF/context.xml
Search for following lines in this file.
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />
Comment out these lines as follows.
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />-->
Similarly, repeat the above step for following file.
# vi /opt/tomcat/webapps/host-manager/META-INF/context.xml
Create a systemd unit to define a service for your Java application server.
# vi /usr/lib/systemd/system/tomcat.service
Add following directives in this file.
[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
Execute following command to notify systemd that you have created a new unit file.
# systemctl daemon-reload
Enable and start Tomcat service.
# systemctl enable --now tomcat.service Created symlink /etc/systemd/system/multi-user.target.wants/tomcat.service → /usr/lib/systemd/system/tomcat.service.
Verify the status of Tomcat service.
# systemctl status tomcat.service
● tomcat.service - Apache Tomcat Server
Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled; vendor pr>
Active: active (running) since Tue 2022-12-13 09:17:12 CST; 15s ago
Process: 15601 ExecStart=/opt/tomcat/bin/catalina.sh start (code=exited, st>
Main PID: 15612 (java)
Tasks: 28 (limit: 4463)
Memory: 85.0M
CPU: 10.879s
CGroup: /system.slice/tomcat.service
└─15612 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat/>
Dec 13 09:17:12 tomcat-01.centlinux.com systemd[1]: Starting Apache Tomcat Serv>
Dec 13 09:17:12 tomcat-01.centlinux.com catalina.sh[15601]: Tomcat started.
Dec 13 09:17:12 tomcat-01.centlinux.com systemd[1]: Started Apache Tomcat Serve>
Allow the Tomcat default service port 8080/tcp in Linux firewall, to make it accessible across the network.
# firewall-cmd --permanent --add-port=8080/tcp success # firewall-cmd --reload success
Open URL http://tomcat-01.centlinux.com:8080/ in a web browser.
Click on “Server Status” button to check you Java application server status.
Go back and click on “Application Manager”. You may need to login by using the credentials that you have defined in tomcat-users.xml file.
Unlock the potential of your web applications by mastering the installation of Apache Tomcat on Rocky Linux 9. With our comprehensive guide, you’ll seamlessly integrate this powerful servlet container into your development and deployment workflow. Let this tutorial be your gateway to building and hosting dynamic, Java-based web applications with ease and efficiency. To start using your Java application server, we recommend that you should have Tomcat: The Definitive Guide (PAID LINK) by O’Reilly Media as a quick reference.
Puppy Linux is a fast, lightweight OS designed for speed and simplicity, perfect for old…
Learn how to change Apache document root in Linux by following this step-by-step guide. Adjust…
Discover how to change Apache port in Linux easily. Follow our simple guide to modify…
Learn how to create a virtual host in Apache Server with this comprehensive guide. Set…
Discover 10 practical tasks for the RHCSA exam with step-by-step solutions. Boost your Linux skills…
Discover the ultimate Fail2ban configuration guide. Learn how to set up, customize, and optimize Fail2ban…
This website uses cookies.