Installing Tomcat on Ubuntu - cloudeguru/How-To-Install GitHub Wiki
# Let's see the step by step by step guide on how to install tomcat on ubuntu.
-
Launch your ubuntu instance and login to it
-
Install java in it. Follow the link on How to Install Java on Ubuntu OS.
-
Move to /opt directory by running below command
cd /opt -
Get the the tar link of the tomcat version you want to download from Tomcat Download Site
-
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
-
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 -
Switch to root user using below command
sudo su -
Untar the downloaded package by running below command
tar -xzvf apache-tomcat-10.1.23.tar.gz -
Now rename the tomcat package to a short name by running below command
mv apache-tomcat-10.1.23 tomcat10 -
Go inside bin directory by running below command
cd tomcat10/binand runsh startup.sh -
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.
-
Now type http://host-ip:8080 in your browser and you can see your tomcat running.
-
Now if you will click on Manager App , you will get 403 Access Denied.
-
To mitigate the above error go inside webapps manager section by running below command
cd /opt/tomcat10/webapps/manager/META-INF -
Now edit context.xml by running below command
vim context.xml
-
You will see something like
<!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis 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 withthe License. You may obtain a copy of the License athttp://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>
- 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>
-
Now save the file.
-
Saved context.xml looks like
- Now if you will refresh your tomcat home page it will ask for credentials.
-
Now move inside tomcat conf directory
cd /opt/tomcat10/conf -
Now edit tomcat-users.xml file. Remove everything from the file and add below content. To remove everything
>tomcat-users.xmlNow runvim 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>
- Now refresh the page and use Username: admin and Password: admin. Now you should see a page like
- Now lets download a sample webapp inside webapp's directory
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

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