Monday, March 12, 2018

How to Install Latest Apache Tomcat 8.5.29 in Ubuntu 16.04


###################### Step 1: Installing Java 8 ######################

- install openjdk-8-jdk or just downlaod and install oracle jdk
sudo apt-get install default-jdk default-jdk-headless

or

- Download jdk form oracle.com
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

- Create installation directory
sudo mkdir /opt/java

- Extract files to installation directory
sudo tar zxvf /tmp/jdk-*-linux-x64.tar.gz -C /opt/java/

- Rename java directory to cool name
sudo mv /opt/java/jdk1.8.*/ /opt/java/jdk8

- Setting Oracle JDK as the default JVM
sudo update-alternatives --install /usr/bin/java java /opt/java/jdk8/bin/java 100
sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk8/bin/javac 100

- Verify java & javac installation

###################### Step 2: Download and Install Apache Tomcat 8 ######################

- Download and check tomcat installation files
cd /tmp
wget http://www-eu.apache.org/dist/tomcat/tomcat-8/v8.5.29/bin/apache-tomcat-8.5.29.zip
wget https://www.apache.org/dist/tomcat/tomcat-8/v8.5.29/bin/apache-tomcat-8.5.29.zip.sha512
sha512sum -c apache-tomcat-8.5.29.zip.sha512

- Create installation directory and extract files
sudo mkdir /opt/tomcat
sudo unzip /tmp/apache-tomcat-*.zip -d /opt/tomcat/

- Rename tomcat extracted directory to cool name
sudo mv /opt/tomcat/apache-tomcat-*/ /opt/tomcat/tomcat8

- Change all scripts *.sh executable only for root as,
sudo chmod 700 /opt/tomcat/tomcat8/bin/*.sh

- Create Symbolic link for startup script as,
sudo ln -s /opt/tomcat/tomcat8/bin/startup.sh /usr/bin/tomcatup

- Create Symbolic link for shutdown script as,
sudo ln -s /opt/tomcat/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown

- start tomcat, you just need to fire the below command as root from anywhere in the shell.
sudo tomcatup

- Once ‘Tomcat Started‘, you can point your browser to http://127.0.0.1:8080

###################### Step 3: Changing Apache Tomcat Port ######################

- First shutdown tomcat server simply by typing the below command from anywhere in the shell.

# tomcatdown

- Next, open ‘/opt/tomcat/tomcat8/conf/server.xml‘ file in your favorite editor (mine is nano) to edit. Change port 8080 to 137, save and exit.
sudo nano /opt/tomcat/tomcat8/conf/server.xml
change:
    <Connector port="8080" protocol="HTTP/1.1"
To:
    <Connector port="137" protocol="HTTP/1.1"

###################### Step 4: Configuring Apache Tomcat 8 ######################

- Add user accounts for admins and managers to access admin and other sections like Server Status, Manager App and Host Manager by add the following lines just before ‘</tomcat-users>‘

sudo nano /opt/tomcat/tomcat8/conf/tomcat-users.xml

<role rolename="admin-gui"/>
<user username="admin" password="admin123" roles="admin-gui"/>
<role rolename="manager-gui"/>
<user username="manager" password="manager123" roles="manager-gui"/>

- Access host-manager & manager remotely by edit context.xml file and comment <Valve> tag using <!-- and -->
sudo nano /opt/tomcat/tomcat8/webapps/host-manager/META-INF/context.xml
<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Lin$
-->

sudo nano /opt/tomcat/tomcat8/webapps/manager/META-INF/context.xml
<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Lin$
-->

No comments:

Post a Comment