Installing Tomcat on Ubuntu - cloudeguru/How-To-Install GitHub Wiki

KloudBlogs Youtube

image

# Let's see the step by step by step guide on how to install tomcat on ubuntu.

  1. Launch your ubuntu instance and login to it

  2. Install java in it. Follow the link on How to Install Java on Ubuntu OS.

  3. Move to /opt directory by running below command

    cd /opt

  4. Get the the tar link of the tomcat version you want to download from Tomcat Download Site

  5. In this demonstration we are going to download tomcat 10. Below is the link to download tomcat 10.

    https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.23/bin/apache-tomcat-10.1.23.tar.gz

image
  1. Now use wget to download tomcat

    sudo wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.23/bin/apache-tomcat-10.1.23.tar.gz

  2. Switch to root user using below command

    sudo su

  3. Untar the downloaded package by running below command

    tar -xzvf apache-tomcat-10.1.23.tar.gz

  4. Now rename the tomcat package to a short name by running below command

    mv apache-tomcat-10.1.23 tomcat10

  5. Go inside bin directory by running below command

    cd tomcat10/bin and run sh startup.sh

  6. If you are running an EC2 instance for this tomcat server make sure to allow 8080 custom TCP port in security group inbound rule. Tomcat's default port is 8080.

  7. Now type http://host-ip:8080 in your browser and you can see your tomcat running.

image
  1. Now if you will click on Manager App , you will get 403 Access Denied.

  2. To mitigate the above error go inside webapps manager section by running below command

    cd /opt/tomcat10/webapps/manager/META-INF

  3. Now edit context.xml by running below command

vim context.xml

  1. You will see something like

    <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <Context antiResourceLocking="false" privileged="true" > <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" sameSiteCookies="strict" /> <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(?:\)?|java\.util\.(?:Linked)?HashMap"/> </Context>

  1. Now change Valve value to allow everything . So the edited version will be

<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

  `http://www.apache.org/licenses/LICENSE-2.0`

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <Context antiResourceLocking="false" privileged="true" > <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" sameSiteCookies="strict" /> <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow=".*" /> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\)?|java\.util\.(?:Linked)?HashMap"/> </Context>

  1. Now save the file.

  2. Saved context.xml looks like

image
  1. Now if you will refresh your tomcat home page it will ask for credentials.
image
  1. Now move inside tomcat conf directory

    cd /opt/tomcat10/conf

  2. Now edit tomcat-users.xml file. Remove everything from the file and add below content. To remove everything >tomcat-users.xml Now run vim tomcat-users.xml

and add below content and save and quit.

   <tomcat-users>
     <role rolename="manager-gui"/>
     <user username="admin" password="admin" roles="manager-gui, manager-script, manager-admin, manager-status"/>
  </tomcat-users>
  1. Now refresh the page and use Username: admin and Password: admin. Now you should see a page like
image
  1. Now lets download a sample webapp inside webapp's directory

Hello World War file

Move inside webapp directory cd /opt/tomcat10/webapps and run wget https://raw.githubusercontent.com/aeimer/java-example-helloworld-war/master/dist/helloworld.war

and refresh your tomcat page. You should see something like image

Congratulation !!! Now your app is up and running. If you find these helpful please share this with your friends and Pls subscribe to our channel for more such awesome videos. KloudBlogs Youtube

image
⚠️ **GitHub.com Fallback** ⚠️