Apache Tomcat 9.0.24 Installation in CentOS 7

Step-By-Step Tutorial

Apache Tomcat (earlier known as Jakarta Tomcat) is an open-source web server developed by Apache Foundation to provide a pure Java HTTP server, which will enable you to run Java files easily, which means that Tomcat is not a normal server like Apache or Nginx, because its main goal is to provide a good web environment to run Java applications only unlike other normal web servers.

Recently, in August, 2019, Apache Tomcat reached to version 9 (i.e. 9.0.24).This Apache Tomcat 9 version comes with numerous improvements as compared to previous Tomcat 8 version.

Some of noticeable changes included in this release are: support for Java Servlet 3.1, JavaServer Pages 2.3, Java Websocket 1.0, etc. and other numerous fixes for issues, as well as number of other enhancements and changes.

Step 1: Installing and Configuring Java 8

Before heading up for the Tomcat installation, make sure you must have JAVA installed on your Linux box to run Tomcat. If not, install the latest version of JAVA 9 or use the following yum command to install available Java (i.e version 8) from the default repositories.

yum install java-1.8.0 -y

Once Java installed, you can verify the newly installed JAVA version running the following command on your system.

java -version
Sample Output
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

Step 2: Installing Apache Tomcat 9

After installing JAVA on the system, now it’s time to download latest version of Apache Tomcat (i.e. 9.0.24) is the most recent stable version at the time of writing this article. If you want to make a cross check, head over to following Apache download page and check if there is a newer version available.

Now download the latest version of Apache Tomcat 9, using following wget command and setup it as shown.

cd /usr/local
wget https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.24/bin/apache-tomcat-9.0.24.tar.gz
tar -xvf apache-tomcat-9.0.24.tar.gz
mv mv apache-tomcat-9.0.24 tomcat9

Note: Replace the version number above with the latest version available if it was different.

Before starting the Tomcat Service, configure CATALINA_HOME environment variable in your system using following command.

echo "export CATALINA_HOME="/usr/local/tomcat9"" >> ~/.bashrc
source ~/.bashrc

Now we all set to start the tomcat web server using the scripts provided by the tomcat package.

cd /usr/local/tomcat9/bin
Sample Output
Using CATALINA_BASE:   /usr/local/tomcat9
Using CATALINA_HOME:   /usr/local/tomcat9
Using CATALINA_TMPDIR: /usr/local/tomcat9/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat9/bin/bootstrap.jar:/usr/local/tomcat9/bin/tomcat-juli.jar
Tomcat started.

Now to open Tomcat from your browser, go to your IP or domain with the 8080 port (because Tomcat will always run on the 8080 port) as an example: mydomain.com:8080, replace mydomain.com with your IP or domain.

Verify Apache Tomcat

The default directory for Tomcat files will be in /usr/local/tomcat9, you can view the configuration files inside the conf folder, the main page that you seen above, when you open your website on the 8080 port is in /usr/local/tomcat9/webapps/ROOT/.

Step 3: Configuring Apache Tomcat 9

By default you only able to access default Tomcat page, to access admin and other sections like Server StatusManager App and Host Manager. You need to configure user accounts for admins and managers.

To do so, you need to edit ‘tomcat-users.xml‘ file located under  /usr/local/tomcat9/conf directory.

Setup Tomcat User Accounts

For example, to assign the manager-gui role to a user named ‘anwera‘ with a password ‘AnweRa‘, add the following line of code to the config file inside the section.

vi /usr/local/tomcat9/conf/tomcat-users.xml
<role rolename="manager-gui"/>
<user username="anwer" password="anwer" roles="manager-gui"/>

Similarly, you can also add ‘admin-gui‘ role to a admin user named ‘admin‘ with a password ‘adm!n‘ as shown below.

<role rolename="admin-gui"/>
<user username="admin" password="admin" roles="admin-gui"/>
Configure Apache Tomcat User Roles

After setting up the admin and managers roles, restart the Tomcat and then try to access the admin section.


Now click on ‘Server Status‘ tab, it will prompt you to enter user credentials, enter username and password that you’ve added above in config file.

Apache Tomcat User Login

Once, you enter user credentials, you will find a page similar to below. If you get 403 Access Denied Error, follow next step.

Monitor Apache Tomcat Server Status

If you receive 403 Access Denied after clicking Server Status, Host Manager or Manager App on Tomcat 8 without prompting for user/password, follow below solution:

Find the CATALINA_HOME/webapps/manager/META-INF/context.xml file and add the comment markers around the Valve.

<Context antiResourceLocking="false" privileged="true" >

<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />


Changing Apache Tomcat Port

If you want to run Tomcat on different port say 80 port. You will have to edit the ‘server.xml‘ file in ‘/usr/local/tomcat9/conf/‘. Before changing, port, make sure to stop the Tomcat server using.


Now open the server.xml file using the Vi editor.

vi /usr/local/tomcat9/conf/server.xml

Now search for “Connector port” and change its value from 8080 to 80 or any other port you want as it follows.

Change Apache Tomcat Port

To save the file and restart the Apache Tomcat server again, using below command.


That’s it, you server will be running on the 80 port.

To get some information about your running Tomcat server and your computer, run.

Tomcat Tomcat

That’s it! Now you can start deploying JAVA based applications under Apache Tomcat 9. For more about on how to deploy applications and create virtual hosts, check out the official Tomcat documentation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s