Apache Tomcat installation in Linux

0
616

Apache Tomcat

Apache Tomcat, often referred to as Tomcat, is an open-source web server developed by the Apache Software Foundation . Tomcat implements several Java EE specifications including Java Servlet, JavaServer Pages (JSP), Java EL, and WebSocket, and provides a “pure Java” HTTP web server environment in which Java code can run.

This is widely used in web development arena for build java based dynamic sites. It will run well on GNU/Linux, BSD, Solaris, Microsoft Windows and Mac OS X operating systems. It is available for download as binary and source archives in both 32-bit and 64-bit architectures.

JAVA Installation

First Change the directory to where the Java to be installed.

[root@localhost ~]# cd /opt/
[root@localhost opt]#wget http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz
[root@localhost opt]#tar xzf jdk-8u91-linux-x64.tar.gz
[root@localhost opt]# cd jdk1.8.0_91/
[root@localhost jdk1.8.0_91]# alternatives --install /usr/bin/java java /opt/jdk1.8.0_91/bin/java 2
[root@localhost jdk1.8.0_91]# alternatives --config java

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1      /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el7_2.x86_64/jre/bin/java
*  2      /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64/jre/bin/java
 + 3      /opt/jdk1.7.0_79/bin/java
   4      /opt/jdk1.8.0_91/bin/java

Enter to keep the current selection[+], or type selection number: 4
[root@localhost jdk1.8.0_91]#java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
[root@localhost jdk1.8.0_91]#alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_91/bin/jar 2
[root@localhost jdk1.8.0_91]#alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_91/bin/javac 2
[root@localhost jdk1.8.0_91]#alternatives --set jar /opt/jdk1.8.0_91/bin/jar
[root@localhost jdk1.8.0_91]#alternatives --set javac /opt/jdk1.8.0_91/bin/javac
[root@localhost jdk1.8.0_91]#export JAVA_HOME=/opt/jdk1.8.0_91
[root@localhost jdk1.8.0_91]#export JRE_HOME=/opt/jdk1.8.0_91/jre
[root@localhost jdk1.8.0_91]#export PATH=$PATH:/opt/jdk1.8.0_91/bin:/opt/jdk1.8.0_91/jre/bin

Tomcat Installation

We can Download the Apache tomcat by uisng the following command or from their official site.

[root@localhost ~]#wget http://mirror.fibergrid.in/apache/tomcat/tomcat-8/v8.5.3/bin/apache-tomcat-8.5.3.tar.gz

Once the Download completed successfully, extract it by using tar command as follows

[root@localhost ~]# tar xzf apache-tomcat-8.5.3.tar.gz

After that copy the apache-tomcat-8.5.3 to /var/lib/ directory.

Installation of Tomcat from binary package requires the creation of user tomcat, After that change the ownership of tomcat folder and files. Then set the CATALINA_HOME and CATALINA_BASE as follows

[root@localhost ~]#export CATALINA_HOME=/var/lib/apache-tomcat-8.5.3
[root@localhost ~]#export CATALINA_BASE=/var/lib/apache-tomcat-8.5.3

Start and stop Tomcat using the following scripts

$CATALINA_HOME/bin/startup.sh
$CATALINA_HOME/bin/shutdown.sh

By default, Tomcat listens on port 8080.we can access web interface by using the address http://ipaddress:8080

apache tomcat homepage

Enabling HTML Management Access in Apache Tomcat

Edit the “$CATALINA_HOME/conf/tomcat-users.xml” file, adding the following entries inside “tomcat-users” tag. Adjust the password as required.

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

Comments

comments