Last updated on May 5th, 2016 at 01:36 am
Install tomcat 7 on Linux, I am using Centos 7.0 for this tutorial
Install and configure tomcat in 5 steps and Enable security for Tomcat Web Application Manager
1)Download Tomcat 7 from https://tomcat.apache.org/download-70.cgi
Direct download link I have used here is http://www.us.apache.org/dist/tomcat/tomcat-7/v7.0.67/bin/apache-tomcat-7.0.67.zip
2)Login to your linux machine using SSH and follow the below commands to install Tomcat 7
cd /opt [[email protected] opt]# wget http://www.us.apache.org/dist/tomcat/tomcat-7/v7.0.67/bin/apache-tomcat-7.0.67.zip [[email protected] opt]# unzip apache-tomcat-7.0.67.zip [[email protected] opt]# mv apache-tomcat-7.0.67 tomcat7
3)Install Java 1.7 & Test the version.
[[email protected] opt]# yum install java-1.7.0-openjdk.x86_64 [[email protected] opt]# java -version java version "1.7.0_95" OpenJDK Runtime Environment (rhel-2.6.4.0.el7_2-x86_64 u95-b00) OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode) [[email protected] opt]#
4) Start Tomcat 7 by going to /opt/tomcat7/bin/startup.sh
[[email protected] bin]# ./startup.sh Using CATALINA_BASE: /opt/tomcat7 Using CATALINA_HOME: /opt/tomcat7 Using CATALINA_TMPDIR: /opt/tomcat7/temp Using JRE_HOME: /usr Using CLASSPATH: /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar Tomcat started. [[email protected] bin]#
5) Login to Tomcat by going to http://localhost:8080
If this is not working check which port Tomcat is listening to by using the netstat command.
Sample Output
[[email protected] opt]# netstat -anp|grep java tcp6 0 0 :::43554 :::* LISTEN 4463/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 4463/java tcp6 0 0 :::8009 :::* LISTEN 4463/java tcp6 0 0 :::8080 :::* LISTEN 4463/java tcp6 0 0 :::35700 :::* LISTEN 4463/java udp6 0 0 :::33848 :::* 4463/java udp6 0 0 :::5353 :::* 4463/java unix 2 [ ] STREAM CONNECTED 51403 4463/java unix 2 [ ] STREAM CONNECTED 52436 4463/java [[email protected] opt]#
Enable Security On Tomcat Web Application Manager
Go to tomcat7 configuration directory /opt/tomcat7/conf
Take a backup of tomcat-users.xml. And then remove the comments inside
<tomcat-users> </tomcat-users>
section by remove < -- and -->
<role rolename="tomcat"/> <role rolename="role1"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="role1" password="tomcat" roles="role1"/>
Then add this just before the closing tag
<role rolename="manager-gui"/> <user username="tomcat" password="somepassword" roles="manager-gui"/>
Now the entire section will look like the one below
<tomcat-users> <!-- NOTE: By default, no user is included in the "manager-gui" role required to operate the "/manager/html" web application. If you wish to use this app, you must define such a user - the username and password are arbitrary. --> <!-- NOTE: The sample user and role entries below are wrapped in a comment and thus are ignored when reading this file. Do not forget to remove <!.. ..> that surrounds them. --> <role rolename="tomcat"/> <role rolename="role1"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="role1" password="tomcat" roles="role1"/> <role rolename="manager-gui"/> <user username="tomcat" password="somepassword" roles="manager-gui"/> </tomcat-users>
Save the file. Restart tomcat.
Now go to URL http://localhost:8080/manager/html and provide the username as “tomcat” password as “somepassword”