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

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

Set Up Nginx Load Balancing

About Load Balancing Loadbalancing is a useful mechanism to distribute incoming traffic around several capable Virtual Private servers. By apportioning the processing mechanism to several machines, redundancy is provided to the application -- ensuring fault tolerance and heightened stability. The Round Robin algorithm for load balancing sends visitors to one of a set of IPs. At its most basic level Round Robin, which is fairly easy to implement, distributes server load without implementing considering more nuanced factors like server response time and the visitors’ geographic region. Setup The steps in this tutorial require the user to have root privileges on your VPS. Prior to setting up nginx loadbalancing, you should have nginx installed on your VPS. You can install it quickly with apt-get: sudo apt-get install nginx Upstream Module In order to set up a round robin load balancer, we will need to use the nginx upstream module. We will incorporate the conf