How To Install Tomcat 8 On CentOS 7

by
Share this Article: Facebook0Google+0Twitter16LinkedIn0Reddit0StumbleUpon1

From the Apache Tomcat home page,

Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies. The Java Servlet and JavaServer Pages specifications are developed under the Java Community Process. Apache Tomcat is developed in an open and participatory environment and released under the Apache License version 2. Apache Tomcat is intended to be a collaboration of the best-of-breed developers from around the world. Apache Tomcat powers numerous large-scale, mission-critical web applications across a diverse range of industries and organizations.

Install Java 1.7 or higher

yum install java-1.7.0-openjdk.x86_64  -y

java  -version
java version "1.7.0_65"
OpenJDK Runtime Environment (rhel-2.5.1.2.el7_0-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
[root@unixmen-centos7 bin]#

Download latest Tomcat 8 release

[root@unixmen-centos7 ~]# cd /opt
[root@unixmen-centos7 opt]# wget http://ftp.nluug.nl/internet/apache/tomcat/tomcat-8/v8.0.9/bin/apache-tomcat-8.0.9.zip

Extract it using command:

unzip apache-tomcat-8.0.9.zip

Move the extracted contents to /opt/ directory.

mv apache-tomcat-8.0.9/ /opt/tomcat

Setup Tomcat environment variable

Create a file called tomcat.sh under /etc/profile.d/ directory.

vi /etc/profile.d/tomcat.sh
#Add the following contents:

#!/bin/bash
CATALINA_HOME=/opt/tomcat
PATH=$CATALINA_HOME/bin:$PATH
export PATH CATALINA_HOME
export CLASSPATH=.

Save and close the file. Make it executable using the following command.

chmod +x /etc/profile.d/tomcat.sh

Then, set the environment variables permanently by running the following command:

source /etc/profile.d/tomcat.sh

Now, we have to start the Tomcat server. Before starting Tomcat, give executable permission to the following script files.

chmod +x $CATALINA_HOME/bin/startup.sh
chmod +x $CATALINA_HOME/bin/shutdown.sh
chmod +x $CATALINA_HOME/bin/catalina.sh

Start Tomcat server by running the following command from your Terminal.

cd $CATALINA_HOME/bin
./startup.sh

[root@unixmen-centos7 bin]# ./startup.sh
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@unixmen-centos7 bin]#

Check if tomcat listening:

[root@unixmen-centos7 bin]# netstat -an | grep 8080
tcp6 0 0 :::8080 :::* LISTEN

Add the port to the firewall and reload:

[root@unixmen-centos7 bin]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
[root@unixmen-centos7 bin]# firewall-cmd --reload

Add the users and the roles under conf/tomcat-users.xml:

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

Restart Tomcat:

./bin//catalina.sh stop
./bin//catalina.sh start

Check http://ip:8080.

Done!

Tomcat tomcat-admin Tomcat-manager

For questions please refer to our Q/A forum at : http://ask.unixmen.com/

Share this Article: Facebook0Google+0Twitter16LinkedIn0Reddit0StumbleUpon1