1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head xmlns="http://www.w3.org/1999/xhtml">
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title xmlns="">Apache Tomcat</title>
7
<link rel="stylesheet" href="../../libs/ubuntu-book.css" type="text/css" />
8
<link rel="home" href="index.html" title="Ubuntu Server Guide" />
9
<link rel="up" href="web-servers.html" title="Chapter 10. Web Servers" />
10
<link rel="prev" href="ruby-on-rails.html" title="Ruby on Rails" />
11
<link rel="next" href="databases.html" title="Chapter 11. Databases" />
12
<link rel="copyright" href="legal.html" title="Credits and License" />
16
<img id="topcap" alt="" src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-top.png" />
17
<div id="layout" class="container clear-block">
18
<script xmlns="" src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script>
19
<script xmlns="" type="text/javascript">
20
_uacct = "UA-1018242-8";
24
<div id="logo-floater">
26
<a href="https://help.ubuntu.com" title="Ubuntu Documentation">
27
<img alt="Ubuntu" id="logo" src="https://help.ubuntu.com/htdocs/ubuntunew/img/logo.png" />
32
<form action="http://www.google.com/cse" id="cse-search-box">
34
<input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />
35
<input type="hidden" name="ie" value="UTF-8" />
36
<input type="text" name="q" size="27" />
37
<input type="submit" name="sa" value="Search" />
42
document.write('<form action="https://help.ubuntu.com/search.html" id="cse-search-box">');
43
document.write(' <div>');
44
document.write(' <input type="hidden" name="cof" value="FORID:9" />');
45
document.write(' <input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />');
46
document.write(' <input type="hidden" name="ie" value="UTF-8" />');
47
document.write(' <input type="text" name="q" size="27" />');
48
document.write(' <input type="submit" name="sa" value="Search" />');
49
document.write(' </div>');
50
document.write('</form>');
53
<a href="https://help.ubuntu.com/">
54
<img alt="Official Documentation" src="https://help.ubuntu.com/htdocs/ubuntunew/img/help-about.png" />
55
<span>Official Documentation</span>
61
<div class="breadcrumbs"><a href="https://help.ubuntu.com/">Ubuntu Documentation</a> > <a href="https://help.ubuntu.com/11.04">Ubuntu 11.04</a> > <span class="breadcrumb-link"><a href="index.html">Ubuntu Server Guide</a></span> > <span class="breadcrumb-link"><a href="web-servers.html">Web Servers</a></span> > <span class="breadcrumb-node">Apache Tomcat</span></div>
62
<div xmlns="http://www.w3.org/1999/xhtml" class="sect1" title="Apache Tomcat">
63
<div class="titlepage">
66
<h2 class="title" style="clear: both"><a id="tomcat"></a>Apache Tomcat</h2>
70
<p>Apache Tomcat is a web container that allows you to serve Java Servlets
71
and JSP (Java Server Pages) web applications.</p>
72
<p>The Tomcat 6.0 packages in Ubuntu support
73
two different ways of running Tomcat. You can install them as a classic
74
unique system-wide instance, that will be started at boot time will run
75
as the tomcat6 unprivileged user. But you can also deploy private
76
instances that will run with your own user rights, and that you should
77
start and stop by yourself. This second way is particularly useful in a
78
development server context where multiple users need to test on their own
79
private Tomcat instances.</p>
80
<div class="sect2" title="System-wide installation">
81
<div class="titlepage">
84
<h3 class="title"><a id="tomcat-installation"></a>System-wide installation</h3>
88
<p>To install the Tomcat server,
89
you can enter the following command in the terminal prompt:</p>
91
<span class="command"><strong>sudo apt-get install tomcat6</strong></span>
93
<p>This will install a Tomcat server with just a default ROOT webapp
94
that displays a minimal "It works" page by default.</p>
96
<div class="sect2" title="Configuration">
97
<div class="titlepage">
100
<h3 class="title"><a id="tomcat-configuration"></a>Configuration</h3>
104
<p>Tomcat configuration files can be found in
105
<code class="filename">/etc/tomcat6</code>. Only a few common configuration tweaks
106
will be described here, please see
107
<a class="ulink" href="http://tomcat.apache.org/tomcat-6.0-doc/index.html" target="_top">Tomcat
108
6.0 documentation</a> for more.</p>
109
<div class="sect3" title="Changing default ports">
110
<div class="titlepage">
113
<h4 class="title"><a id="tomcat-configuration-ports"></a>Changing default ports</h4>
117
<p>By default Tomcat 6.0 runs a HTTP connector on port 8080 and an
118
AJP connector on port 8009. You might want to change those default
119
ports to avoid conflict with another server on the system. This is
120
done by changing the following lines in
121
<code class="filename">/etc/tomcat6/server.xml</code>:</p>
122
<pre class="programlisting">
123
<Connector port="8080" protocol="HTTP/1.1"
124
connectionTimeout="20000"
125
redirectPort="8443" />
127
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
130
<div class="sect3" title="Changing JVM used">
131
<div class="titlepage">
134
<h4 class="title"><a id="tomcat-configuration-jvm"></a>Changing JVM used</h4>
138
<p>By default Tomcat will run preferably with OpenJDK-6, then try
139
Sun's JVM, then try some other JVMs. If you have various JVMs
140
installed, you can set which should be used by setting JAVA_HOME in
141
<code class="filename">/etc/default/tomcat6</code>:</p>
142
<pre class="programlisting">
143
JAVA_HOME=/usr/lib/jvm/java-6-sun
146
<div class="sect3" title="Declaring users and roles">
147
<div class="titlepage">
150
<h4 class="title"><a id="tomcat-configuration-users"></a>Declaring users and roles</h4>
154
<p>Usernames, passwords and roles (groups) can be defined centrally
155
in a Servlet container. In Tomcat 6.0 this is done in the
156
<code class="filename">/etc/tomcat6/tomcat-users.xml</code> file:</p>
157
<pre class="programlisting">
158
<role rolename="admin"/>
159
<user username="tomcat" password="s3cret" roles="admin"/>
163
<div class="sect2" title="Using Tomcat standard webapps">
164
<div class="titlepage">
167
<h3 class="title"><a id="tomcat-webapps"></a>Using Tomcat standard webapps</h3>
171
<p>Tomcat is shipped with webapps that you can install
172
for documentation, administration or demo purposes.</p>
173
<div class="sect3" title="Tomcat documentation">
174
<div class="titlepage">
177
<h4 class="title"><a id="tomcat-installation-docs"></a>Tomcat documentation</h4>
181
<p>The <span class="application"><strong>tomcat6-docs</strong></span> package contains
182
Tomcat 6.0 documentation, packaged as a webapp that you can access by
183
default at http://yourserver:8080/docs. You can install it by entering
184
the following command in the terminal prompt:</p>
186
<span class="command"><strong>sudo apt-get install tomcat6-docs</strong></span>
189
<div class="sect3" title="Tomcat administration webapps">
190
<div class="titlepage">
193
<h4 class="title"><a id="tomcat-installation-admin"></a>Tomcat administration webapps</h4>
197
<p>The <span class="application"><strong>tomcat6-admin</strong></span> package contains
198
two webapps that can be used to administer the Tomcat server using a
199
web interface. You can install them by entering the
200
following command in the terminal prompt:</p>
202
<span class="command"><strong>sudo apt-get install tomcat6-admin</strong></span>
204
<p>The first one is the <span class="emphasis"><em>manager</em></span> webapp, which
205
you can access by default at http://yourserver:8080/manager/html. It is
206
primarily used to get server status and restart webapps.</p>
207
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
208
<table border="0" summary="Note">
210
<td rowspan="2" align="center" valign="top" width="25">
211
<img alt="[Note]" src="../../libs/admon/note.png" />
213
<th align="left"></th>
216
<td align="left" valign="top">
217
<p>Access to the <span class="emphasis"><em>manager</em></span> application is
218
protected by default: you need to define a user with the role "manager"
219
in <code class="filename">/etc/tomcat6/tomcat-users.xml</code>
220
before you can access it.</p>
225
<p>The second one is the <span class="emphasis"><em>host-manager</em></span> webapp,
226
which you can access by default at
227
http://yourserver:8080/host-manager/html.
228
It can be used to create virtual hosts dynamically.</p>
229
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
230
<table border="0" summary="Note">
232
<td rowspan="2" align="center" valign="top" width="25">
233
<img alt="[Note]" src="../../libs/admon/note.png" />
235
<th align="left"></th>
238
<td align="left" valign="top">
239
<p>Access to the <span class="emphasis"><em>host-manager</em></span> application is
240
also protected by default: you
241
need to define a user with the role "admin" in
242
<code class="filename">/etc/tomcat6/tomcat-users.xml</code>
243
before you can access it.</p>
248
<p>For security reasons, the tomcat6 user cannot write to the
249
<code class="filename">/etc/tomcat6</code> directory by default. Some features
250
in these admin webapps (application deployment, virtual host creation)
251
need write access to that directory. If you want to use these
252
features execute the following, to give users in the tomcat6 group the necessary
255
<span class="command"><strong>sudo chgrp -R tomcat6 /etc/tomcat6</strong></span>
256
<span class="command"><strong>sudo chmod -R g+w /etc/tomcat6</strong></span>
259
<div class="sect3" title="Tomcat examples webapps">
260
<div class="titlepage">
263
<h4 class="title"><a id="tomcat-installation-examples"></a>Tomcat examples webapps</h4>
267
<p>The <span class="application"><strong>tomcat6-examples</strong></span> package contains
268
two webapps that can be used to test or demonstrate Servlets and JSP
269
features, which you can access them by default at
270
http://yourserver:8080/examples. You can install them by entering the
271
following command in the terminal prompt:</p>
273
<span class="command"><strong>sudo apt-get install tomcat6-examples</strong></span>
277
<div class="sect2" title="Using private instances">
278
<div class="titlepage">
281
<h3 class="title"><a id="tomcat-user"></a>Using private instances</h3>
285
<p>Tomcat is heavily used in development and testing scenarios
286
where using a single system-wide instance doesn't meet the requirements
287
of multiple users on a single system. The Tomcat 6.0 packages in
288
Ubuntu come with tools to help deploy your own user-oriented instances,
289
allowing every user on a system to run (without root rights) separate
290
private instances while still using the system-installed
292
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
293
<table border="0" summary="Note">
295
<td rowspan="2" align="center" valign="top" width="25">
296
<img alt="[Note]" src="../../libs/admon/note.png" />
298
<th align="left"></th>
301
<td align="left" valign="top">
302
<p>It is possible to run the system-wide instance and the private
303
instances in parallel, as long as they do not use the same TCP
309
<div class="sect3" title="Installing private instance support">
310
<div class="titlepage">
313
<h4 class="title"><a id="tomcat-user-install"></a>Installing private instance support</h4>
317
<p>You can install everything necessary to run private instances
318
by entering the following command in the terminal prompt:</p>
320
<span class="command"><strong>sudo apt-get install tomcat6-user</strong></span>
323
<div class="sect3" title="Creating a private instance">
324
<div class="titlepage">
327
<h4 class="title"><a id="tomcat-user-create"></a>Creating a private instance</h4>
331
<p>You can create a private instance directory by entering the
332
following command in the terminal prompt:</p>
334
<span class="command"><strong>tomcat6-instance-create my-instance</strong></span>
336
<p>This will create a new <code class="filename">my-instance</code> directory
337
with all the necessary subdirectories and scripts.
338
You can for example install your common libraries in the
339
<code class="filename">lib/</code> subdirectory and deploy your webapps in the
340
<code class="filename">webapps/</code> subdirectory. No webapps are deployed
343
<div class="sect3" title="Configuring your private instance">
344
<div class="titlepage">
347
<h4 class="title"><a id="tomcat-user-config"></a>Configuring your private instance</h4>
351
<p>You will find the classic Tomcat configuration files for your
352
private instance in the <code class="filename">conf/</code>
353
subdirectory. You should for
354
example certainly edit the <code class="filename">conf/server.xml</code> file
355
to change the default ports used by your private Tomcat instance to
356
avoid conflict with other instances that might be running.</p>
358
<div class="sect3" title="Starting/stopping your private instance">
359
<div class="titlepage">
362
<h4 class="title"><a id="tomcat-user-start"></a>Starting/stopping your private instance</h4>
366
<p>You can start your private instance by entering the following
367
command in the terminal prompt (supposing your instance is located
368
in the <code class="filename">my-instance</code> directory):</p>
370
<span class="command"><strong>my-instance/bin/startup.sh</strong></span>
372
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
373
<table border="0" summary="Note">
375
<td rowspan="2" align="center" valign="top" width="25">
376
<img alt="[Note]" src="../../libs/admon/note.png" />
378
<th align="left"></th>
381
<td align="left" valign="top">
382
<p>You should check the <code class="filename">logs/</code> subdirectory for
383
any error. If you have a <span class="emphasis"><em>java.net.BindException: Address
384
already in use<null>:8080</em></span> error, it means that the
385
port you're using is already taken and that you should change it.
391
<p>You can stop your instance by entering the following
392
command in the terminal prompt (supposing your instance is located
393
in the <code class="filename">my-instance</code> directory):</p>
395
<span class="command"><strong>my-instance/bin/shutdown.sh</strong></span>
399
<div class="sect2" title="References">
400
<div class="titlepage">
403
<h3 class="title"><a id="tomcat-references"></a>References</h3>
407
<div class="itemizedlist">
408
<ul class="itemizedlist" type="disc">
409
<li class="listitem">
411
See the <a class="ulink" href="http://tomcat.apache.org/" target="_top">Apache Tomcat</a> website for more information.
414
<li class="listitem">
416
<a class="ulink" href="http://oreilly.com/catalog/9780596003180/" target="_top">Tomcat: The Definitive Guide</a> is a good
417
resource for building web applications with Tomcat.
420
<li class="listitem">
422
For additional books see the <a class="ulink" href="http://wiki.apache.org/tomcat/Tomcat/Books" target="_top">Tomcat Books</a> list page.
425
<li class="listitem">
427
Also, see the<a class="ulink" href="https://help.ubuntu.com/community/ApacheTomcat5" target="_top">Ubuntu Wiki Apache Tomcat</a> page.
435
<div xmlns="http://www.w3.org/1999/xhtml" class="navfooter">
437
<table width="100%" summary="Navigation footer">
439
<td width="40%" align="left"><a accesskey="p" href="ruby-on-rails.html"><img src="../../libs/navig/prev.png" alt="Prev" /></a> </td>
440
<td width="20%" align="center">
441
<a accesskey="u" href="web-servers.html">
442
<img src="../../libs/navig/up.png" alt="Up" />
445
<td width="40%" align="right"> <a accesskey="n" href="databases.html"><img src="../../libs/navig/next.png" alt="Next" /></a></td>
448
<td width="40%" align="left" valign="top">Ruby on Rails </td>
449
<td width="20%" align="center">
450
<a accesskey="h" href="index.html">
451
<img src="../../libs/navig/home.png" alt="Home" />
454
<td width="40%" align="right" valign="top"> Chapter 11. Databases</td>
460
<div id="ubuntulinks">
461
<p>The material in this document is available under a free license, see <a href="/legal.html">Legal</a> for details<br />
462
For information on contributing see the <a href="https://wiki.ubuntu.com/DocumentationTeam">Ubuntu Documentation Team wiki page</a>. To report a problem, visit the <a href="https://bugs.launchpad.net/ubuntu/+source/ubuntu-docs">bug page for Ubuntu Documentation</a></p>
466
<img src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-bottom.png" alt="" />