How To Install Apache Tomcat on CentOS 7

Published: February 14, 2018 (Updated: Feb 14, 2018)

Enjoying this content? Subscribe to the Channel!

The Ultimate Guide: Installing Apache Tomcat 7 on CentOS 7 Linux (Step-by-Step Tutorial)

Welcome back to Darren’s Tech Tutorials!

Apache Tomcat is the gold standard when it comes to serving Java web applications. As an open-source implementation of Java Servlet, JavaServer Pages (JSP), and Java WebSocket technologies, Tomcat is the critical engine that powers countless enterprise and modern web environments.

If you are running a robust CentOS 7 server and need a reliable home for your Java projects, this is the tutorial for you!

In this comprehensive guide, we will walk you through the essential steps to install, configure, and secure Apache Tomcat version 7 on your CentOS 7 system, ensuring you are ready to deploy your applications quickly and efficiently.


Prerequisites and Preparation

Before we begin the installation process, ensure your CentOS 7 server is updated and you have the necessary environment installed.

1. Update the System

Always start with a quick system update:

sudo yum update -y

2. Install Java Development Kit (JDK)

Tomcat is a Java application server, meaning Java must be properly installed and configured. Tomcat 7 requires JDK 6 or newer.

Note: If you haven’t installed Java yet, you must do so now. Ensure you have the JAVA_HOME environment variable set correctly, as this is critical for Tomcat’s configuration files later.


Step 1: Downloading and Extracting Apache Tomcat 7

We recommend installing Tomcat into the /opt directory, which is standard practice for optional software packages on Linux systems.

1. Navigate to the Installation Directory

Use cd to move to the preferred location:

cd /opt

2. Download the Tomcat 7 Archive

We will use a secure method (like wget) to download the official Tomcat 7 binary distribution. For the exact download URL and command syntax, please refer to the full command tutorial linked at the end of this post.

3. Extract the Archive

Once downloaded, extract the compressed file. We will then rename the directory to something simple like tomcat7 for easier management:

# Example extraction and renaming
sudo tar -xvzf apache-tomcat-7.x.xx.tar.gz
sudo mv apache-tomcat-7.x.xx tomcat7

Step 2: Configuring the Tomcat Environment

To ensure Tomcat can locate Java and run smoothly, we need to explicitly define its environment variables.

1. Set the JAVA_HOME and CATALINA_HOME

You will need to edit a core configuration file (often found within the /opt/tomcat7/bin directory, such as catalina.sh) or a system-wide environment file to define the following paths:

  • JAVA_HOME: Points to your Java installation.
  • CATALINA_HOME: Points to the Tomcat installation directory (/opt/tomcat7).

Defining these paths prevents startup errors and ensures the server correctly finds all necessary dependencies.

2. Configure Required Web Applications and Documentation

The Tomcat distribution often comes in separate packages for the core server, the web applications (like the Tomcat Home page), and the documentation. You will download the necessary webapps and documentation packages separately and place them within your webapps directory inside your Tomcat installation.

Step 3: Configuring the Tomcat Manager GUI Login

The Tomcat Manager allows you to deploy, undeploy, start, and stop applications remotely via a browser-based Graphical User Interface (GUI). For security, this access must be explicitly configured.

1. Edit the tomcat-users.xml File

Navigate to the Tomcat configuration directory (usually /opt/tomcat7/conf/) and open the tomcat-users.xml file.

This file defines the users, passwords, and assigned roles. To enable the Manager GUI and the Admin GUI, you must define at least one user with the appropriate roles:

<tomcat-users>
    <!-- Define the roles needed for administration -->
    <role rolename="manager-gui"/>
    <role rolename="admin-gui"/>

    <!-- Define a new user and assign the required roles -->
    <user username="adminuser" password="YourSecurePassword" roles="manager-gui,admin-gui"/>
</tomcat-users>

Security Reminder: Always use a complex, unique password for your Tomcat manager account.

2. Update Context Files (If Needed)

Depending on your network setup, you may need to edit the context files for the Manager and Host applications to allow connections from external IP addresses (not just localhost). This is a common step if you plan to manage Tomcat from a remote machine.

Step 4: Starting the Tomcat Service and Verification

With configuration complete, it’s time to fire up the service!

1. Start Tomcat

Execute the startup script from the bin directory:

/opt/tomcat7/bin/startup.sh

2. Check the Status

Verify that Tomcat has started successfully:

tail -f /opt/tomcat7/logs/catalina.out

Look for a message confirming that the service has started in milliseconds.

3. Open the Firewall (CentOS 7)

CentOS 7 uses firewalld. Tomcat runs on port 8080 by default, so you must open this port to allow external access:

sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

4. Access Tomcat in Your Browser

Open your web browser and navigate to your server’s IP address or hostname on port 8080:

http://[Your_Server_IP]:8080

You should now see the Apache Tomcat default welcome page! You can also click on the Manager App link and log in using the credentials you defined in Step 3.


Conclusion: Ready for Java Deployment!

Congratulations! You have successfully downloaded, configured, and launched Apache Tomcat 7 on your CentOS 7 machine. Your server is now a powerful environment ready to host your Java servlets, JSPs, and web applications.

This installation provides a secure foundation for all your Java development needs, from small personal projects to robust enterprise solutions.

Did you find this tutorial helpful? If so, hit that Like button and subscribe to Darren’s Tech Tutorials for more clear, actionable guides!


Need the full command list? You can find the complete, copy-paste tutorial with every command used here: https://darrenoneill.eu/?p=472

Don’t forget to subscribe to the channel for weekly tech insights! https://goo.gl/ajiwW2