Tomcat Documentation V1.0
Tomcat Documentation V1.0
Tomcat Documentation V1.0
Tomcat
Introduction
Tomcat or Apache Tomcat is a light weight, open source web container used to deploy and
running the java based web applications, developed by Apache Software Foundation (ASF).
What is Webserver?
A Web server is a program that uses HTTP (Hypertext Transfer Protocol) protocol to serves web
content (HTML and static content) to users.
Examples
Apache HTTP server
Nginx (pronounced engine X)
IBM HTTP server (IHS)
Oracle iplanet web server
Internet Information Server (IIS)
Examples
Apache Tomcat
JBoss/WildFly - RedHat
WebLogic - Oracle
WebSphere Application Server - IBM
WebSphere Liberty Profile - IBM
Galssfish
Tomcat installation
Tomcat software will available as a zip file. So, we can unzip it and use as follows.
Step 1: Create the folder called Apache in any directory and Unzip apache software into that
folder.
Step 2: Open the command prompt and execute the below commands.
>cd C:\DevOps\Apache\apache-tomcat-7.0.79\bin
>startup.bat (OR) > catalina.bat start ---> Starting the Tomcat server.
MAC/Linux:
sh startup.sh (OR) > sh catalina.sh start ---> Starting the Tomcat server.
Once you execute the startup.bat, you will see below screens.
lib: Keeps the JAR-file that are available to all webapps. The default installation include servlet-
api.jar (Servlet), jasper.jar (JSP) and jasper-el.jar (EL). You may also keep the JAR files of
external package here, such as MySQL JDBC driver (mysql-connector-java-5.1.{xx}-bin.jar)
and JSTL (jstl.jar and standard.jar).
logs: contains the engine logfile Catalina.{yyyy-mm-dd}.log, host logfile localhost.{yyyy-mm-
dd}.log, and other application logfiles such as manger and host-manager. The access log (created
by the AccessLogValve) is also kept here.
webapps: the default appBase - web applications base directory of the host localhost.
work: contains the translated servlet source files and classes of JSP/JSF. Organized in hierarchy
of engine name (Catalina), host name (localhost), webapp name, followed by the Java classes
package structure.
temp: temporary files.
---------------------------------------------------------------------------------------------------------------------
How to change the port number in Tomcat?
Go to the conf directory and open the server.xml and you will find below lines.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Replace the 8080 with any port number.
---------------------------------------------------------------------------------------------------------------------
How to stop the tomcat server?
>cd APACHE_HOME Dir\bin
>shutdown.bat (OR) > catalina.bat stop
MAC/Linux:
shutdown.sh (OR) > catalina.sh stop
---------------------------------------------------------------------------------------------------------------------
Install Tomcat in Linux
cd /opt
wget http://apache.spinellicreations.com/tomcat/tomcat-9/v9.0.16/bin/apache-tomcat-9.0.16.zip
unzip apache-tomcat-9.0.16.zip
cd /opt/apache-tomcat-9.0.16/bin
chmod u+x *.sh
#sh /opt/apache-tomcat-9.0.16/bin/startup.sh
ln -s /opt/apache-tomcat-9.0.16/bin/startup.sh /usr/bin/startTomcat
ln -s /opt/apache-tomcat-9.0.16/bin/shutdown.sh /usr/bin/stopTomcat
Admin Console
Tomcat provides a web based administration console which can be started via the following link:
http://localhost:8080/manager/html
Tomcat manager is the web application, using this we manage applications running
on tomcat. By default access is restricted to this application.
<!-- Note: While copy pate above line you have to remove double quotes and type manually. -->
<user username="admin" password="admin" roles="manager-gui,admin-gui"/>
<user username="mithun" password="passw0rd" roles="manager-gui,admin-gui"/>
</tomcat-users>
To access the server status application and Manager app, tomcat 7 onwards below roles as
introduced.
manager-gui : allows access to the HTML GUI and the Server Status and Manager App
pages
admin-gui : allows access to the Host Manager page.
If you provide add below line in tomcat-users.xml, we will get the access for below
apps(Buttons)
<user username="admin" password="passw0rd" roles="manager-gui"/>
http://localhost:8083/manager/status
http://localhost:8083/manager/html
Host Manager
To access the host manager application, tomcat 7 onwards below roles as introduced.
admin-gui - allows access to the HTML GUI
If you provide add below line in tomcat-users.xml, we will get the access for below
apps(Buttons)
<user username="admin" password="passw0rd" roles="admin-gui"/>
http://localhost:8083/host-manager/html
---------------------------------------------------------------------------------------------------------------------
Stop the server
Deployment
Deploying the application in Tomcat server is nothing but, putting war file in Tomcat’s
webapps directly.
For every application deployment need to restart the tomcat server.
Once the server restart, tomcat starts it will unpack the war and make the application available.
---------------------------------------------------------------------------------------------------------------------
Error 1
Solution:
If you see this error set the class path for Java.
---------------------------------------------------------------------------------------------------------------------
Error 2:
Solution:
---------------------------------------------------------------------------------------------------------------------
Tomcat Performance Tuning
References
http://tomcat.apache.org/tomcat-7.0-doc/setup.html ---> Installing Apache Tomcat
http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html --->Windows service
HOW-TO
https://wiki.apache.org/tomcat/TomcatVersions