Apache Tomcat on CentOS: A Comprehensive Guide
Introduction Apache Tomcat is an open-source web server and servlet container developed by the Apache Software Foundation. It is widely used to host Java-based web applications. CentOS, on the other hand, is a free and open-source operating system based on Red Hat Enterprise Linux. In this article, we will discuss how to install and configure Apache Tomcat on CentOS.

Prerequisites Before installing Apache Tomcat on CentOS, ensure that you have the following prerequisites:
- CentOS 7 or later
- A user with sudo privileges
- Java Development Kit (JDK) installed
- Apache Yum Repository enabled
Step 1: Install Java Development Kit (JDK) To run Java applications, you need to install the JDK. You can install it using the following command:
sudo yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel
Step 2: Enable Apache Yum Repository To access the Apache Tomcat package, you need to enable the Apache Yum Repository. Add the following repository to your system:
sudo yum localrepo http://download.fedoraproject.org/pub/epel/7/x86_64/
Step 3: Install Apache Tomcat Now, install Apache Tomcat using the following command:
sudo yum install tomcat
After the installation is complete, you can verify the installation by checking the status of the Tomcat service:
sudo systemctl status tomcat
Step 4: Configure Apache Tomcat By default, Apache Tomcat runs on port 8080. If you want to change the port or configure other settings, you can edit the tomcat.service file located in /etc/systemd/system/.

sudo nano /etc/systemd/system/tomcat.service
Find the following line:
ExecStart=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.x86_64/bin/java -Djava.util.logging.config.file=/usr/share/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/share/tomcat/endorsed -Dcatalina.base=/usr/share/tomcat -Dcatalina.home=/usr/share/tomcat -Dcatalina.tmpdir=/usr/share/tomcat/temp -Djava.io.tmpdir=/usr/share/tomcat/temp -Xms512m -Xmx1024m -jar /usr/share/tomcat/bin/tomcat.jar
You can modify the -Xms and -Xmx values to adjust the memory settings. For example, to set the maximum heap size to 2GB, change the line to:
-Xms512m -Xmx2048m
Save the file and exit the editor. Now, restart the Tomcat service to apply the changes:
sudo systemctl restart tomcat
Step 5: Accessing Apache Tomcat To access the Apache Tomcat web interface, open a web browser and navigate to the following URL:
http://localhost:8080 You should see the Apache Tomcat welcome page.
FAQs

How do I check the version of Apache Tomcat installed on CentOS? To check the version of Apache Tomcat installed on CentOS, use the following command:
cat /usr/share/tomcat/bin/version
- How do I change the default port for Apache Tomcat? To change the default port for Apache Tomcat, edit the
tomcat.servicefile located in/etc/systemd/system/. Find the following line:
ExecStart=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.x86_64/bin/java ...
Add the -Dcatalina.base=/usr/share/tomcat parameter to the line:
ExecStart=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.x86_64/bin/java -Dcatalina.base=/usr/share/tomcat -Dcatalina.home=/usr/share/tomcat -Dcatalina.tmpdir=/usr/share/tomcat/temp -Djava.io.tmpdir=/usr/share/tomcat/temp -Dcatalina.port=8080 -jar /usr/share/tomcat/bin/tomcat.jar
Replace 8080 with your desired port number. Save the file and restart the Tomcat service to apply the changes.

