Installing Apache Tomcat 8.5 on CentOS 7.3

This tutorial shows, how you can install Apache Tomcat 8.5 on CentOS 7.3.

Apache Tomcat ?

Yes, Lets see about Apache Tomcat, an open source Java Servlet implementation developed by the Apache Software Foundation. Beside Java Servlets, Tomcat implements several Java server technologies including JavaServer Pages (JSP), Java Expression Language, and Java WebSocket. Tomcat provides an HTTP Web Server for Java applications with support for HTTP/2, OpenSSL for JSSE and TLS virtual hosting.

Lets go for  further proceedings.

Prerequisites for installing

  • Server with CentOS 7 – 64bit
  • 2 GB or more RAM (Recommended)
  • Root Privileges on the server

Step 1 – Install Java (JRE and JDK)

As a first thing, we need to install Java JRE and JDK from the CentOS repository. We will install Java 1.8.13 on the server.

# yum -y install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64

It will take some time, wait until the installation finished. After completing the installation check the Java version.

# java -version

You will get the below result

[root@webhostingchennai ~]# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
[root@webhostingchennai ~]#

Step 2 – Configuring the Java Home Environment

In the first step, we have installed Java, and now we need to configure the JAVA_HOME environment variable on the CentOS server so that Java applications can find the right Java version and also the Tomcat requires the JAVA_HOME environment to be setup properly.

Before, configuring the JAVA_HOME environment, we need to know where the Java directory is.

To check the Java directory

# sudo update-alternatives --config java

Java Directoy = “/usr/lib/jvm/java-1.8.0-openjdk-”

Now, we can proceed with editing the environment file.

# nano /etc/environment

Add the JAVA_HOME environment variable by adding


Save the file and exit.

Next, edit the .bash_profile file and add the JAVA_HOME variable as well

# nano ~/.bash_profile

Add the below lines at end of the file.

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-
export PATH=$JAVA_HOME/bin:$PATH

Save the file and exit.

Now, we need to reload the bash profile file.

# source ~/.bash_profile

Make sure there is no error while reloading the bash file, Finally check the JAVA_HOME environment variable.

# echo $JAVA_HOME

You will get the output as below,

[root@webhostingchennai ~]# echo $JAVA_HOME
[root@webhostingchennai ~]#

Step 3 – Install Apache Tomcat 8.5

The most interesting thing in this knowledge base, Installing Tomcat.

As a important thing we to know here is, installing Apache Tomcat under the user tomcat.

Let we create a user and group named tomcat.

# groupadd tomcat
# useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Note that,

  • -s /bin/false –  disable shell access
  • -g tomcat – assign new user to the group tomcat
  • -d /opt/tomcat – define the home directory for the user

Now, go to the /opt directory and download tomcat.

# cd /opt/
# wget

Extract Tomcat and move all the files and directories that are in the ‘apache-tomcat-8.5.6’ directory to the ‘tomcat’ directory.

# tar -xzvf apache-tomcat-8.5.6.tar.gz
# mv apache-tomcat-8.5.6/* tomcat/

Next, change the owner of the tomcat directory to the “tomcat” user and group.

# chown -hR tomcat:tomcat tomcat

Yeah.. Finally you have installed Apache Tomcat. 🙂

Step 4 – Test Apache Tomcat

Now, we just want to run a short test to make sure there are no errors in our installation.

Go to, /opt/tomcat/bin/ directory and run the command ‘’ to test Apache Tomcat.

# cd /opt/tomcat/bin/
# ./

You will get the out as follows,

[root@webhostingchennai bin]# ./
Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-1.8.0-openjdk-
Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@webhostingchennai bin]#

Tomcat is using port 8080 now, check the open port on the server with the netstat command.

# netstat -plntu

Note : If netstat command is not working, you have to install net-tools using,

# yum install net-tools

You will get the output for netstat -plntu as

Now, visit the server IP address with port 8080, with a web browser(your_server_ip:8080). You will see the Apache Tomcat default page.

Now, stop Apache Tomcat , because we need to run Tomcat with a systemd service file in the final configuration. Also  make sure the tomcat directory is owned by the “tomcat” user and group.

# cd /opt/tomcat/bin/
# ./ 
# chown -hR tomcat:tomcat /opt/tomcat/
[root@webhostingchennai bin]# cd /opt/tomcat/bin/
[root@webhostingchennai bin]# ./
Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-1.8.0-openjdk-
Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
[root@webhostingchennai bin]# chown -hR tomcat:tomcat /opt/tomcat/
[root@webhostingchennai bin]#

Step 5 – Setup Apache Tomcat Service

Now,we need to run Apache Tomcat as tomcat user with a systemd service file for easy starting and stopping of the service. So the next step is to create a ‘tomcat.service’ file.

Go to the systemd system directory and create a new file ‘tomcat.service’.

# cd /etc/systemd/system/
# touch tomcat.service
# nano tomcat.service

Paste the configuration below:

Description=Apache Tomcat 8 Servlet Container



Save the file and exit from tomcat.service file.

Now, we have to reload the systemd daemon, then start and add the Apache Tomcat service at boot time.

# systemctl daemon-reload
# systemctl start tomcat
# systemctl enable tomcat

Now check that tomcat is running by checking the open port 8080. and check the status.

# netstat -plntu
# systemctl status tomcat

Step 6 – Configure Apache Tomcat Users

Here, we need to configure the users for Apache Tomcat. Tomcat is installed, and it’s running by default on port 8080, we can access it with a web browser, but we can not access the site-manager dashboard yet. To enable and configure Tomcat users, edit the file ‘tomcat-users.xml’.

Go to the tomcat configuration directory and edit the tomcat-users.xml file.

# cd /opt/tomcat/conf/
# nano tomcat-users.xml

Create a new line under line 43 and paste below configuration.

<role rolename=”manager-gui”/>
<user username=”admin” password=”password” roles=”manager-gui,admin-gui”/>

Save and exit from tomcat-users.xml.

NOTE: Don’t forget to remove the commented marks ( <!– … –> )

Your user configurations should be as follows

<role rolename="tomcat"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<role rolename="manager"/>
<user username="admin" password="EQcJhHW4Ud" roles="manager-gui,manager-status,admin-gui,manager"/>

Next, go to the manager directory and edit the context.xml file.

# cd /opt/tomcat/webapps/manager/META-INF/
# nano context.xml

Comment or remove the below lines from this file.

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

Now, Save the file and exit.

Go to the host-manager directory and edit the context.xml file again.

# cd /opt/tomcat/webapps/host-manager/META-INF/
# nano context.xml

Comment or remove the below lines from this file.

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

Save the file and exit, then restart tomcat.

# systemctl restart tomcat

Step 7 – Configure Firewalld

In CentOS 7, we have a default firewall tool named firewalld. It replaces the iptables interface and connects to the Netfilter kernel code.

Here, we will start the firewalld service and open port 8080 so we can access the Apache Tomcat server from the outside of the network.

Start the firewalld service and add it to start at boot time.

# systemctl start firewalld
# systemctl enable firewalld

Next, add the apache tomcat port 8080 to the firewall, and reload the firewalld service.

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

Check that all the services are available in the firewall and check that the Apache Tomcat port 8080 is open.

# firewall-cmd --list-ports
# firewall-cmd --list-services

Now, Apache Tomcat port 8080 is accessible from outside of the network, and the ssh port is open by default as well.

Step 8 – Testing Apache Tomcat

Now, open your web browser and type in your server IP with port 8080. You will see the Apache Tomcat default page.


Go to the manager dashboard with below URL ,


Now go to Tomcat Virtual Host Manager dashboard with URL



Hurray.. Now, you have installed Apache Tomcat 8.5 on your centOS 7.3 Server.


You may also like...

2 Responses

  1. Darjeeling says:

    Good afternoon. Many thanks 🙂 Really enjoyed reading this page.

  2. Raja ram says:

    Thanks, nice blog.

    Your blog solved my problem, was struggling to install tomcat in my server.

    My hosting provider silicon house gave me many links nothing worked, followed your blog I was able to install with your easy understand words.

    Thank you once again.

Leave a Reply

Your email address will not be published.