Skip to main content

How To Install Apache Tomcat on Ubuntu

Apache tomcat is a Java based application server released by the Apache Software Foundation. It is a web server and a servlet container for Java web applications.

Setup

Tomcat installation on a virtual private server is relatively easy. Its single required dependency is Java and this tutorial will include a step on how to install that platform.
You do need to have a user with sudo privileges for this tutorial.


There are two basic ways to install Tomcat on Ubuntu:

  • Install through apt-get. This is the simplest method. 
  • Download the binary distribution from the Apache Tomcat site.

Step One—Install Through apt-get

 
The first thing you will want to do is update your apt-get package lists:
 
sudo apt-get update 

The most recent version of Tomcat is 7, and it can be easily downloaded through apt-get 

sudo apt-get install tomcat7
 
Install additional packages  

sudo apt-get install tomcat7-docs tomcat7-admin tomcat7-examples
 
 

Step Two—Install Through Binary Distribution

To download tomcat from their site, copy the link for the tar.gz package under the “Core” section and begin the download. You will get a link that originates from one of Apache’s many mirrors, making the command look mostly like this (although coming from a different site).

wget http://mirrors.ispros.com.bd/apache/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz

After the download completes, untar the file.

tar xvzf apache-tomcat-7.0.29.tar.gz
 
We first see the  tomcat directory structure
 
here each folder uses following purpose.
bin -  It contains all binary and script files for running tomcat.
lib - contains all shared libraries used for tomcat
conf - contains configuration information like which port tomcat can bind , etc...
logs - it contain all logging details
temp - this folder tomcat used for temporary files purpose
webapps - this folder is very important. here we put all application war files.
work - If application contain any jsp then jsp is translated and converted into servlet its stores here.


When we run Tomcat, it uses 5 environment variables. They are:
  • CATALINA_HOME
  • CATALINA_BASE
  • CATALINA_TMPDIR
  • JRE_HOME/JAVA_HOME
  • CLASSPATH

In the above list, CATALINA_HOME and JAVA_HOME are mandatory environment variables. All others are optional and can be calculated using CATALINA_HOME.
CATALINA_HOME – this environment variable should point to tomcat base folder, where tomcat binary are  installed/extracted. so based on CATALINA_HOME we can get bin and lib folder
CATALINA_BASE – If we not specified then CATALINA_HOME value is set. This variable pointed to configuration and webapps folder. Based on this variable server uses conf, logs, temp, webapps, work folders.


Step Three—Configure .bashrc

 In order to start Tomcat, we need to add it as an environment variable in the /.bashrc file.

sudo nano ~/.bashrc
 
You can add this information to the end of the file:
export JAVA_HOME=/usr/lib/jvm/default-java
export PATH=$JAVA_HOME/bin:$PATH 
export CATALINA_HOME=~/path/to/tomcat
 
Save and exit out of .bashrc. You can make the changes effective by restarting the bashrc file.

. ~/.bashrc
 

Step Four—RUN

Tomcat is now installed and configured on our virtual servers. However, it is not yet activated.

The final step is to activate Tomcat by running its startup script:

$CATALINA_HOME/bin/startup.sh
 
Once that runs, Tomcat is up and ready on port 8080.
You can visually verify that Tomcat is working by accessing your server page at your_IP_address:8080.

It should look like

Tomcat Installation

Let's take a look at the Web Application Manager, accessible via the link or http://your_ip_address:8080/manager/:

tomcat manager

 
 



 

 

Comments

Popular posts from this blog

JavaMelody: Monitoring the Performance of Tomcat Application Server

Javamelody is an opensource (LGPL) application to monitor Java or Java EE application servers in QA and production environments. JavaMelody is mainly based on statistics of requests and on evolution charts. (Extract from the Javamelody home page) It allows to improve applications in QA and production Give facts about the average response times and number of executions Make decisions when trends are bad, before problems become too serious Optimize based on the more limiting response times Find the root causes of response times Verify the real improvement after optimization It includes summary charts showing the evolution over time of the following indicators: Number of executions, mean execution times and percentage of errors of http requests, sql requests, jsp pages or methods of business façades (if EJB3, Spring or Guice) Java memory Java CPU Number of user sessions Number of jdbc connections These charts can be viewed on the current day, week, month, year or cu...

Java HotSpot VM Settings

The following JVM parameters are recommended: -Djava.awt.headless=true  -Dfile.encoding=UTF-8  -server  -Xms512m  -Xmx1024m  -XX:NewSize=256m  -XX:MaxNewSize=256m  -XX:PermSize=256m  -XX:MaxPermSize=256m  -XX:+DisableExplicitGC -Djava.awt.headless=true Headless mode is a system configuration in which the display device, keyboard, or mouse is lacking. Sounds unexpected, but actually you can perform different operations in this mode, even with graphic data. -server The JDK includes two flavors of the VM -- a client-side offering, and a VM tuned for server applications. These two solutions share the Java HotSpot runtime environment code base, but use different compilers that are suited to the distinctly unique performance characteristics of clients and servers. These differences include the compilation inlining policy and heap defaults. Although the Server and the Client VMs are similar, the Serv...

Configuring URL Encoding on Tomcat Application Server

Application servers may have different settings for character encodings. We strongly recommend UTF-8 where possible. By default, Tomcat uses ISO-8859-1 character encoding when decoding URLs received from a browser. This can cause problems when Confluence's encoding is UTF-8, and you are using international characters in the names of attachments or pages. To configure the URL encoding in Tomcat: Step 1 - Configure connector: Edit conf/server.xml and find the line where the Coyote HTTP Connector is defined. It will look something like this, possibly with more parameters: < Connector port = "8080" /> Add a URIEncoding="UTF-8" property to the connector: < Connector port = "8080" protocol = "HTTP/1.1"      connectionTimeout = "20000"      redirectPort = "8443"      URIEncoding = "UTF-8" /> If you are using mod_jk you should appl...