ManagedCloud Servers

High performance handled and monitored by us 24/7/365. A complete solution to provide you with our in house expertise 24/7 tailored to your specific needs. We'll setup a bespoke server for your site using the latest technologies so you can get the most out of your hardware and get your website loading quickly and reliably. Find out more..

cPanelCloud Servers

Recommended - High performance cloud servers with no technical knowledge required. If you're hosting multiple websites already and you're looking to consolidate, or if you're looking to isolate yourself from the shared hosting environment but you don't have the time or knoweldge to manage a server, then the Managed cPanel Servers are for you. Find out more..

UnmanagedCloud Servers

Our unmanaged range gives you complete control at rock bottom prices and our cloud platform boasts super fast multipath 40Gb/s network, the latest Intel Xeon V3 CPUs and enterprise grade redundant SSDs. If you're a sysadmin look no further, we offer some of the best specification to price ratio servers available. Find out more..

Want your very own server? Get our 1GB memory, Xeon V4, 20GB SSD VPS for £10.00 / month.

Get a Cloud Server

How to Install Apache Tomcat 9 on CentOS 7

The Apache Software Foundation, also known as ASF recently released Apache Tomcat server 9 on December 8, 2016. Tomcat server implements Java servlet and Java servlet technologies like JSP Java WebSocket. Apache Tomcat is an open-source web server and servlet container that is used to serve Java applications.

It is developed by the Apache Software Foundation, written in Java and released under Apache License 2.0.


Tomcat 9 does not require any special kind of hardware it will need a CentOS server, IP Address of your server and root privileges on the server.

Installing Java

Before installing Tomcat we will have to install Java Development Kit (JDK) on our system but it is recommended that you update the system and available packages before installing JDK. Run the following command to update system.

yum -y update

Now once the system is updated install JDK and to do so run following command:

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

The above command will take some time to install JDK so you should wait until the installation process has finished.

When Java is installed check the java version with the following command:

java -version

You'll see a result similar to this :

[root@ip-172-31-16-36 ~]# java -version
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111-b15)
OpenJDK 64-Bit Server VM (build 25.111-b15, mixed mode)
[root@ip-172-31-16-36 ~]#

Java Home Environment

Before you configure Java Home Environment we recommend you to check where the Java directory is and to do so run following command:

sudo update-alternatives --config java

Now edit the environment file with any text editor here we are using nano editor but you can choose anyone you wish.

nano /etc/environment

Now add the Java Home Environment variable as shown below :


yYou can simply copy/paste this to your file.

After adding Java Home Environment save and exit from the editor.

Now we'll have to edit the .bash_profile so run the command given below:

nano ~/.bash_profile

Now add the Home Environment variable as shown below:

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

Save file and exit from the editor.

We recommend you reload the .bash_profile, to do so run following command:

source ~/.bash_profile

We recommend you make sure there is no error in configuring Home Environment variable and also check the Java Home environment variable :


You will see output similar to this containing the path to java directory :

[root@ip-172-31-16-36 ~]# nano ~/.bash_profile
[root@ip-172-31-16-36 ~]# source ~/.bash_profile
[root@ip-172-31-16-36 ~]# echo $JAVA_HOME
[root@ip-172-31-16-36 ~]#

Installing Apache Tomcat 9

We'll have to create a system user and group before proceeding with the installation process of Tomcat so create a user and group named tomcat to run below-given command to do so:

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

The options used in the above command perform the following:

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

Downloading and Installing Apache Tomcat

First, go to the directory /opt and download Apache Tomcat server using wget command from as shown below:

cd /opt/

This will change your current directory to directory /opt/

If in any case you haven't installed wget command on your system then first of all install it using this command:

yum install wgetwget

Now extract using tar command as below :

tar -xzvf apache-tomcat-9.0.0.M15.tar.gz

Move all the files that are in the apache-tomcat-9.0.0.M15 directory to the tomcat directory to do so run following command :

mv apache-tomcat-9.0.0.M15/* tomcat/

Now change the proper ownership using the following command:

chown -hR tomcat:tomcat tomcat

Testing Tomcat

We recommend you to run a short testing on Tomcat to make sure that there is no error and it is installed successfully so follow the below-given process.

Run below given command :

cd /opt/tomcat/bin/ ./

Currently, Tomcat is using port number 8080 so check the open port using netstat command as shown:

netstat -plntu

You can check this using a web browser with http://yourserver_IP:8080 then you'll see the homepage of Apache Tomcat Server but we recommend you to use browser later at final testing because we will run Tomcat with a systemd service file in the final configuration.

Now run following commands :

cd /opt/tomcat/bin/./shutdown.shchown -hR tomcat:tomcat /opt/tomcat/

Creating a systemd Service File

Now you'll need to create a systemd service file to run Apache Tomcat as a tomcat user. Creation of a systemd service file is recommended for easy starting and stopping the service.

Run following command :

nano /etc/systemd/system/tomcat.service

Add the content below into nano text editor, you can simply copy/paste this into the file:

Description=Apache Tomcat 8 Servlet Container

[Service] User=tomcat Group=tomcat Type=forking Environment=CATALINA_PID=/opt/tomcat/ Environment=CATALINA_HOME=/opt/tomcat Environment=CATALINA_BASE=/opt/tomcat ExecStart=/opt/tomcat/bin/ ExecStop=/opt/tomcat/bin/ Restart=on-failure


Save and close the file then run the following commands to start the Tomcat service and enable Tomcat service to start on boot:

systemctl daemon-reload systemctl start tomcat systemctl enable tomcat

Once again check for the open port using netstat command shown below:

netstat -plntu

Now run the command below and make sure that service is active as shown below:

systemctl status tomcat

Configure Tomcat Users

Run following command to edit tomcat-users.xml file using any text editor here we are using nano :

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

Create a new line under line 43 and add following content, again you can simply copy-paste this into file like you've done before:

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

Save the file and exit text editor.

Now you'll have to edit context.xml file using following commands:

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

Now you'll have to comment out line 19 and 20 as shown below:

    <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" /> -->

Save the file and exit nano text editor .

Now once again edit the context.xml file but this time it is in host-manager directory so run below given commands :

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

Comment out again line 19 and 20.

    <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" /> -->

Save the file and exit nano text editor .

Now you'll have to restart the tomcat and to do so run following command:

systemctl restart tomcat

Configure Firewalld

If in any case you haven't installed firewalld on your system then install it first using yum command as shown below:

yum install firewalld

You'll have to start firewalld and add it to start at boot time, to do so run following command:

systemctl start firewalldsystemctl enable firewalld

Now you'll have to use firewall-cmd command to add apache tomcat port number 8080 to the firewall so simply enter below-given command:

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

You'll see a result as "success".

Now reload the firewall service using the following command:

firewall-cmd --reload

We recommend you to check for all service available and port 8080 is open and there is no error, to do so run following command:

firewall-cmd --list-portsfirewall-cmd --list-services

Web Access

Open your web browser and visit server with port number 8080 http://YourserverIPaddress:8080 then you'll see the homepage of Apache Tomcat like shown below:

Click on the Manager app on the top right side of your screen then you'll be asked to username and password for authentication enter your username and password and you will see manager dashboard like this:

You can manage your Java applications using the Tomcat Web Application Manager. It is also used to Start, Stop, Reload, Deploy. You can also diagnostics on your apps using Tomcat Web Application Manager.

Now go to the host manager and here you'll be again asked to enter a username and password so repeat the above procedure and click on login you'll see a virtual host manager dashboard like this:


In this tutorial, we have learned how to install and configure Apache Tomcat 9 server on a CentOS system very easily and we hope that now after this guide you have enough knowledge to work with Tomcat 9.

Want your very own server? Get our 1GB memory, Xeon V4, 20GB SSD VPS for £10.00 / month.

View Plans