Monday, August 1, 2016

How To Install Apache Tomcat 9.0 Ubuntu 16.04

The Apache Tomcat® software is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies.


Step 1 - Install Tomcat from binary 

Download Latest JAVA version from Official Website.

root@U16:~# wget http://apache.mirror.iweb.ca/tomcat/tomcat-9/v9.0.0.M9/bin/apache-tomcat-9.0.0.M9.tar.gz

root@U16:~# wget http://apache.mirror.iweb.ca/tomcat/tomcat-9/v9.0.0.M9/bin/apache-tomcat-9.0.0.M9.tar.gz
--2016-08-01 02:42:30--  http://apache.mirror.iweb.ca/tomcat/tomcat-9/v9.0.0.M9/bin/apache-tomcat-9.0.0.M9.tar.gz
Resolving apache.mirror.iweb.ca (apache.mirror.iweb.ca)... 192.175.120.173, 2607:f748:10:12:a9a:c1:1e:1
Connecting to apache.mirror.iweb.ca (apache.mirror.iweb.ca)|192.175.120.173|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9322413 (8.9M) [application/x-gzip]
Saving to: ‘apache-tomcat-9.0.0.M9.tar.gz’

apache-tomcat-9.0.0.M9.tar.gz              100%[=======================================>]   8.89M   402KB/s    in 38s

2016-08-01 02:43:09 (242 KB/s) - ‘apache-tomcat-9.0.0.M9.tar.gz’ saved [9322413/9322413]

Step 2 - Extract apache-tomcat-9.0.0.M9.tar.gz  file 

root@U16:~# tar -xzvf apache-tomcat-9.0.0.M9.tar.gz
root@U16:~# tar -xzvf apache-tomcat-9.0.0.M9.tar.gz
Step 3 - Move file to a proper location 

root@U16:~# mv apache-tomcat-9.0.0.M9 /opt/tomcat
root@U16:~# mv apache-tomcat-9.0.0.M9 /opt/tomcat


Step 4 - Install JAVA

Java is required to run Tomcat, let's check JAVA if already exist.
root@U16:~# java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

In My Ubuntu machine JAVA 8 is already installed,  If JAVA does't exist Install it using command apt install default-jdk.

root@U16:~# apt install default-jdk


Step 5 - Start TOMCAT 

Ater JAVA installation, Let's start TOMCAT.

Go to Tomcat folder
root@U16:~# cd /opt/tomcat/bin/

To Start Tomcat run command ./startup.sh
root@U16:/opt/tomcat/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@U16:/opt/tomcat/bin#

JAVA  has been started successfully, Let's check using Server IP and Port 8080.


6 - Optional   We can change the default Tomcat port from server.xml file.

6a -Fisrt Stop Tomcat Server -  root@U16:/opt/tomcat/bin# ./shutdown.sh

root@U16:/opt/tomcat/bin# ./shutdown.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

6b - Go to Conf Folder -
root@U16:~# cd /opt/tomcat/conf/

6c - Open server.xml file using VI editor

root@U16:/opt/tomcat/conf# vi server.xml
Find Connector port="8080"  And Change port to your desire number.

<Connector port="8181" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

6d - Save and Exit from file.


6E - Start Tomcat Server


root@U16:/opt/tomcat/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.
JAVA  has been started successfully, Let's check using Server IP and Port 8181.





7- Troubleshooting :-

When you select Server Status, Showing error 403 access denied 















7a- To Fix above error, you need append below syntax in $CATALINA_HOME/conf/Catalina/hostname/manager.xml file. Open file in Vi editor.


root@U16:~# vi /opt/tomcat/conf/Catalina/localhost/manager.xml
<Context antiResourceLocking="false" privileged="true" useHttpOnly="true" override="true">

  <Valve className="org.apache.catalina.authenticator.BasicAuthenticator" securePagesWithPragma="false" />

</Context>

Save and Exit from File.

7b-  Now open tomcat-users.xml file and allow role access from remote pc.


root@U16:~# vi /opt/tomcat/conf/tomcat-users.xml

Add below Syntax to above file between <tomcat-users> </tomcat-users> 
.
 <role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>


Save and Exit from File.
7c- Now Restart Tomcat Server :-

Stop Tomcat First

 root@U16:~# /opt/tomcat/bin/./shutdown.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
root@U16:~#


Start Tomcat Now
root@U16:~# /opt/tomcat/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@U16:~#


7d- Let's check Server Status Now

Enter User_Name (tomcat) and Password (s3cret) when prompt. You will see below page when everything goes successfully.








That's ALL
!!! Cheers !!!

No comments:

Post a Comment