Install and Configure Apache Tomcat 8 on CentOS , Red Hat VPS Server
To run Java applications on the web there is a one web server which provide web server as well as servlet container.Apache server Foundation released open source project Tomcat .
Here we are going install Tomcat 8.0.26 on Linux based servers like CentOs and Red Hat Servers.This installation will support on both version of Red Hat and CentOs 7.X and 6.X.
Main feature in this Tomcat version 8 and release are :
- JSE 2.3
- It supports Java Servlet 3.1
- Java WebSocket 1.0
- Java Unified Expression Language ( EL ) 3.0
Prerequisites to Tomcat 8 and its releases :
Apache Tomcat 8 prerequisites is Java 7 or higher version of java .
Here we are using root user to install and configure apache tomcat server on CentOs server.
Install Java and Check Version :
Java 7 or higher version is required to install tomcat server , Here we have already explain in our other post how to do installation of java on CentOs and Red Hat Server version .
Now I am giving output of my server java version .
# java -version java version "1.8.0_51" Java(TM) SE Runtime Environment (build 1.8.0_51-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Steps for setup Tomcat :
After set up of Java version, now we can start work on apache tomcat 8 using below command , I am working as a root user in my server vm. You can download apache tomcat version form apache tomcat official page or here you can find official page url of tomcat 8 .
Follow below command in setup and configuring.
# cd /tmp # wget http://mirror.metrocast.net/apache/tomcat/tomcat-8/v8.0.26/bin/apache-tomcat-8.0.26.tar.gz # tar xzf apache-tomcat-8.0.26.tar.gz # mv apache-tomcat-8.0.26 /opt
Configuring CATALINA_HOME Environment Variable :
Put the below command to set up environment variable .
# echo "export CATALINA_HOME="/opt/apache-tomcat-8.0.26"" >> ~/.bashrc # source ~/.bashrc
Starting Apache Tomcat Server :
It is very simple to start the service of apache tomcat . Tomcat server works on default 8080 . We can change the default port on application . First we are going to start the server on port 8080 , after that we will change the port from 8080 to another free port.
# cd /opt/apache-tomcat-8.0.26 # ./bin/startup.sh
Output Status of Apache Tomcat:
# ./bin/startup.sh Using CATALINA_BASE: /opt/apache-tomcat-8.0.26 Using CATALINA_HOME: /opt/apache-tomcat-8.0.26 Using CATALINA_TMPDIR: /opt/apache-tomcat-8.0.26/temp Using JRE_HOME: /usr Using CLASSPATH: /opt/apache-tomcat-8.0.26/bin/bootstrap.jar:/opt/apache-tomcat-8.0.26/bin/tomcat-juli.jar Tomcat started.
Apache Tomcat access URL after installation :
After installation of apache tomcat we can access url or IP of server though port 8080 in web browser like below I have tested apache tomcat installation .
Managing Users & Roles :
If you want to manage users and roles of admin,managers for Apache Tomcat , you should know Catalina base and config files used by tomcat apache.We have install Tomcat in /opt folder and set Catalina path in environment variable /opt/apache-tomcat-8.0.26/ , Now here conf/tomcat-users.xml file for secure and manage the admin and manager roles.
You need to search “tomcat-users” script tag in file and in between script tag , edit and put the below content for manager role .
<role rolename="manager-gui"/> <user username="MANAGER_USERNAME" password="MANAGER_PASSWROD" roles="manager-gui"/>
and for both admin and manager previlages , edit and put the below lines in tomcat-users in between script tag .
<role rolename="admin-gui" /> <user username="ADMIN_USERNAME" password="ADMIN_PASSWORD" roles="manager-gui,admin-gui" />
# ./bin/shutdown.sh # ./bin/startup.sh
Now open the URL with your domain name or IP like below .
http://www.example.com:8080/manager/html OR http://www.example.com:8080/manager
Default port change to other :
(1) Locate conf/server.xml in tomcat installation folder ( /opt/apache-tomcat-8.0.2) .
(2) Search “Connector port” text in server.xml . Change the Connector port=”8080″ port to any other port number. Here i have change to 8081 .
<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
(3) save and exit from the server.xml file and restart Tomcat Apache server .