Install Apache Tomcat 9 with Application Manager on CentOS 7 - CentLinux - Installation Guides & HowTos


Sunday, 3 March 2019

Install Apache Tomcat 9 with Application Manager on CentOS 7

Install Apache Tomcat 9 with Manager Apps on CentOS 7

Apache Tomcat is an open source implementation of several Java EE technologies such as Java Servlet, Java Server Pages, Java Expression Language and Java WebSocket. Apache Tomcat provides a Java based web application server on which Java applications can be deployed and run. Apache Tomcat is developed by Apache Software Foundation released under Apache License 2.0.

In this article, we will install Apache Tomcat 9 on CentOS 7 and configure Application Manager to perform server administration conveniently. We recommend you to have Tomcat: The Definitive Guide by O'Reilly Media as reference during your Apache Tomcat journey.


Table of Contents:


System Specification:

We have provisioned a CentOS 7 virtual machine with following specifications.

  • Hostname -
  • IP Address -
  • Operating System - CentOS 7.6
  • Apache Tomcat - 9


Installing OpenJDK 8 on CentOS 7:

Connect with using ssh as root user.

Apache Tomcat 9 requires Java 8 or later JRE (Java Runtime Environment). Therefore, we will install OpenJDK 8 (an open source implementation of Java platform) on CentOS 7 machine.

[root@tomcat-01 ~]# yum install -y java-1.8.0-openjdk-devel ... Installed: java-1.8.0-openjdk-devel.x86_64 1: Dependency Installed: copy-jdk-configs.noarch 0:3.3-10.el7_5 dejavu-fonts-common.noarch 0:2.33-6.el7 dejavu-sans-fonts.noarch 0:2.33-6.el7 fontconfig.x86_64 0:2.13.0-4.3.el7 fontpackages-filesystem.noarch 0:1.44-8.el7 giflib.x86_64 0:4.1.6-9.el7 java-1.8.0-openjdk.x86_64 1: java-1.8.0-openjdk-headless.x86_64 1: javapackages-tools.noarch 0:3.4.1-11.el7 libICE.x86_64 0:1.0.9-9.el7 libSM.x86_64 0:1.2.2-2.el7 libX11.x86_64 0:1.6.5-2.el7 libX11-common.noarch 0:1.6.5-2.el7 libXau.x86_64 0:1.0.8-2.1.el7 libXcomposite.x86_64 0:0.4.4-4.1.el7 libXext.x86_64 0:1.3.3-3.el7 libXi.x86_64 0:1.7.9-1.el7 libXrender.x86_64 0:0.9.10-1.el7 libXtst.x86_64 0:1.2.3-1.el7 libfontenc.x86_64 0:1.1.3-3.el7 libjpeg-turbo.x86_64 0:1.2.90-6.el7 libxcb.x86_64 0:1.13-1.el7 lksctp-tools.x86_64 0:1.0.17-2.el7 python-javapackages.noarch 0:3.4.1-11.el7 python-lxml.x86_64 0:3.2.1-4.el7 ttmkfdir.x86_64 0:3.0.9-42.el7 tzdata-java.noarch 0:2018i-1.el7 xorg-x11-font-utils.x86_64 1:7.5-21.el7 xorg-x11-fonts-Type1.noarch 0:7.5-9.el7 Complete!

Java executables have been automatically added to PATH environment variable. Therefore, we are only required to set the JAVA_HOME environment variable.

[root@tomcat-01 ~]# echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-" >> /etc/profile [root@tomcat-01 ~]# . /etc/profile [root@tomcat-01 ~]# env | grep JAVA_HOME JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-

Verify Java version.

[root@tomcat-01 ~]# java -version openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

OpenJDK 8 has been installed on our CentOS 7 server.

Note: if you are using more than one Java versions on the same machine then you should read our previous article Install Java JDK 11 from RPM/TAR on CentOS 7 to perform additional settings using alternatives command.


Installing Apache Tomcat 9 on CentOS 7:

If we install Apache Tomcat from yum repository, then we do not have to perform following steps manually. But Apache Tomcat 9 is the latest version and it is not yet available in yum repositories. Therefore, we have to install it manually.

Create a user to own Apache Tomcat 9 software.

[root@tomcat-01 ~]# useradd -s /sbin/nologin tomcat

Download Apache Tomcat 9 binaries from Tomcat's website.

[root@tomcat-01 ~]# cd [root@tomcat-01 ~]# wget --2019-03-03 07:58:26-- Resolving ( Connecting to (||:443... connected. HTTP request sent, awaiting response... 200 OK Length: 10783080 (10M) [application/x-gzip] Saving to: âapache-tomcat-9.0.16.tar.gzâ 100%[======================================>] 10,783,080 414KB/s in 17s 2019-03-03 07:58:44 (608 KB/s) - âapache-tomcat-9.0.16.tar.gzâ saved [10783080/10783080]

Extract downloaded tarball of Apache Tomcat 9.

[root@tomcat-01 ~]# tar xvf apache-tomcat-9.0.16.tar.gz ... apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/ apache-tomcat-9.0.16/bin/

Move extracted directory to /opt/tomcat/.

[root@tomcat-01 ~]# mkdir /opt/tomcat [root@tomcat-01 ~]# mv apache-tomcat-9.0.16 /opt/tomcat

Change ownership of /opt/tomcat directory.

[root@tomcat-01 ~]# chown -R tomcat:tomcat /opt/tomcat

We will create a soft link latest for /opt/tomcat/apache-tomcat-9.0.16 directory. So, we can upgrade/downgrade Apache Tomcat conveniently.

[root@tomcat-01 tomcat]# ln -s /opt/tomcat/apache-tomcat-9.0.16/ /opt/tomcat/latest

Create a systemd unit file to define a service for Apache Tomcat 9 server.

[root@tomcat-01 ~]# vi /usr/lib/systemd/system/tomcat.service

and add following lines therein.

[Unit] Description=Tomcat 9 servlet container [Service] Type=forking User=tomcat Group=tomcat Environment="JAVA_HOME=/usr/lib/jvm/jre" Environment="" Environment="CATALINA_BASE=/opt/tomcat/latest" Environment="CATALINA_HOME=/opt/tomcat/latest" Environment="CATALINA_PID=/opt/tomcat/latest/temp/" Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC" ExecStart=/opt/tomcat/latest/bin/ ExecStop=/opt/tomcat/latest/bin/ [Install]

Execute following command to notify systemd that we have created a new unit file.

[root@tomcat-01 ~]# systemctl daemon-reload

Start and enable Apache Tomcat service.

[root@tomcat-01 ~]# systemctl enable tomcat.service Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/tomcat.service. [root@tomcat-01 ~]# systemctl start tomcat.service

Allow Apache Tomcat service port in Linux firewall.

[root@tomcat-01 ~]# firewall-cmd --permanent --add-port=8080/tcp success [root@tomcat-01 ~]# firewall-cmd --reload success

Browse URL in a client's browser.

apache-tomcat default-homepage-01

It will show the default homepage of Apache Tomcat 9.

Apache Tomcat 9 has been installed on our CentOS 7 server.


Configure Apache Tomcat 9 Application Manager on CentOS 7:

Application Manager is installed by default with Apache Tomcat 9. Application Manager provides Web UI to easily manage, deploy, start and stop Java applications running on Apache Tomcat 9 server.

But, we need to configure Managers Apps according to our requirement.

Define users and roles to access Apache Tomcat 9 Manager Web UI.

[root@tomcat-01 ~]# vi /opt/tomcat/latest/conf/tomcat-users.xml

Add following lines just before </tomcat-users> tag.

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

By default Application Manager is allowed to be accessed from localhost only.

We must edit the following files to let us access it from other machines.

[root@tomcat-01 ~]# vi /opt/tomcat/latest/webapps/manager/META-INF/context.xml

Find and comment following lines of code.

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

After comment, it should be looks like this.

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

Similarly, repeat the above step for following file.

[root@tomcat-01 ~]# vi /opt/tomcat/latest/webapps/host-manager/META-INF/context.xml

Restart Apache Tomcat 9 service.

[root@tomcat-01 ~]# systemctl restart tomcat.service

Browse URL using a client's browser.


Click on Server Status.


Go back and click on Manager App.


Go back and click on Host Manager.


Application Manager has been configured on Apache Tomcat 9 running on CentOS 7 server.

No comments:

Post a Comment