blob: d01a13e14fbbebeb2721cc2e1a35cf8a8c219f4b [file] [log] [blame]
Cheng Tang697ce242014-04-27 16:18:17 +08001================================================================================
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16================================================================================
17
18$Id: RUNNING.txt 1456725 2013-03-14 23:48:06Z kkolinko $
19
20 ===================================================
21 Running The Apache Tomcat 7.0 Servlet/JSP Container
22 ===================================================
23
24Apache Tomcat 7.0 requires a Java Standard Edition Runtime
25Environment (JRE) version 6 or later.
26
27=============================
28Running With JRE 6 Or Later
29=============================
30
31(1) Download and Install a Java SE Runtime Environment (JRE)
32
33(1.1) Download a Java SE Runtime Environment (JRE),
34 release version 6 or later, from
35 http://www.oracle.com/technetwork/java/javase/downloads/index.html
36
37(1.2) Install the JRE according to the instructions included with the
38 release.
39
40 You may also use a full Java Development Kit (JDK) rather than just
41 a JRE.
42
43
44(2) Download and Install Apache Tomcat
45
46(2.1) Download a binary distribution of Tomcat from:
47
48 http://tomcat.apache.org/
49
50(2.2) Unpack the binary distribution so that it resides in its own
51 directory (conventionally named "apache-tomcat-[version]").
52
53 For the purposes of the remainder of this document, the name
54 "CATALINA_HOME" is used to refer to the full pathname of that
55 directory.
56
57NOTE: As an alternative to downloading a binary distribution, you can
58create your own from the Tomcat source code, as described in
59"BUILDING.txt". You can either
60
61 a) Do the full "release" build and find the created distribution in the
62 "output/release" directory and then proceed with unpacking as above, or
63
64 b) Do a simple build and use the "output/build" directory as
65 "CATALINA_HOME". Be warned that there are some differences between the
66 contents of the "output/build" directory and a full "release"
67 distribution.
68
69
70(3) Configure Environment Variables
71
72Tomcat is a Java application and does not use environment variables. The
73variables are used by the Tomcat startup scripts. The scripts use the variables
74to prepare the command that starts Tomcat.
75
76(3.1) Set CATALINA_HOME (required) and CATALINA_BASE (optional)
77
78The CATALINA_HOME environment variable should be set to the location of the
79root directory of the "binary" distribution of Tomcat.
80
81An example was given in (2.2) above.
82
83The Tomcat startup scripts have some logic to set this variable
84automatically if it is absent, based on the location of the startup script
85in *nix and on the current directory in Windows. That logic might not work
86in all circumstances, so setting the variable explicitly is recommended.
87
88The CATALINA_BASE environment variable specifies location of the root
89directory of the "active configuration" of Tomcat. It is optional. It
90defaults to be equal to CATALINA_HOME.
91
92Using distinct values for the CATALINA_HOME and CATALINA_BASE variables is
93recommended to simplify further upgrades and maintenance. It is documented
94in the "Multiple Tomcat Instances" section below.
95
96
97(3.2) Set JRE_HOME or JAVA_HOME (required)
98
99These variables are used to specify location of a Java Runtime
100Environment or of a Java Development Kit that is used to start Tomcat.
101
102The JRE_HOME variable is used to specify location of a JRE. The JAVA_HOME
103variable is used to specify location of a JDK.
104
105Using JAVA_HOME provides access to certain additional startup options that
106are not allowed when JRE_HOME is used.
107
108If both JRE_HOME and JAVA_HOME are specified, JRE_HOME is used.
109
110The recommended place to specify these variables is a "setenv" script. See
111below.
112
113
114(3.3) Other variables (optional)
115
116Other environment variables exist, besides the four described above.
117See the comments at the top of catalina.bat or catalina.sh scripts for
118the list and a description of each of them.
119
120One frequently used variable is CATALINA_OPTS. It allows specification of
121additional options for the java command that starts Tomcat.
122
123See the Java documentation for the options that affect the Java Runtime
124Environment.
125
126See the "System Properties" page in the Tomcat Configuration Reference for
127the system properties that are specific to Tomcat.
128
129A similar variable is JAVA_OPTS. It is used less frequently. It allows
130specification of options that are used both to start and to stop Tomcat as well
131as for other commands.
132
133Note: Do not use JAVA_OPTS to specify memory limits. You do not need much
134memory for a small process that is used to stop Tomcat. Those settings
135belong to CATALINA_OPTS.
136
137Another frequently used variable is CATALINA_PID (on *nix only). It
138specifies the location of the file where process id of the forked Tomcat
139java process will be written. This setting is optional. It will enable the
140following features:
141
142 * better protection against duplicate start attempts and
143 * allows forceful termination of Tomcat process when it does not react to
144 the standard shutdown command.
145
146
147(3.4) Using the "setenv" script (optional, recommended)
148
149Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can
150be specified in the "setenv" script. The script is placed either into
151CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named
152setenv.bat (on Windows) or setenv.sh (on *nix). The file has to be
153readable.
154
155By default the setenv script file is absent. If the script file is present
156both in CATALINA_BASE and in CATALINA_HOME, the one in CATALINA_BASE is
157preferred.
158
159For example, to configure the JRE_HOME and CATALINA_PID variables you can
160create the following script file:
161
162On Windows, %CATALINA_BASE%\bin\setenv.bat:
163
164 set "JRE_HOME=%ProgramFiles%\Java\jre6"
165 exit /b 0
166
167On *nix, $CATALINA_BASE/bin/setenv.sh:
168
169 JRE_HOME=/usr/java/latest
170 CATALINA_PID="$CATALINA_BASE/tomcat.pid"
171
172
173The CATALINA_HOME and CATALINA_BASE variables cannot be configured in the
174setenv script, because they are used to locate that file.
175
176All the environment variables described here and the "setenv" script are
177used only if you use the standard scripts to launch Tomcat. For example, if
178you have installed Tomcat as a service on Windows, the service wrapper
179launches Java directly and does not use the script files.
180
181
182(4) Start Up Tomcat
183
184(4.1) Tomcat can be started by executing one of the following commands:
185
186 On Windows:
187
188 %CATALINA_HOME%\bin\startup.bat
189
190 or
191
192 %CATALINA_HOME%\bin\catalina.bat start
193
194 On *nix:
195
196 $CATALINA_HOME/bin/startup.sh
197
198 or
199
200 $CATALINA_HOME/bin/catalina.sh start
201
202(4.2) After startup, the default web applications included with Tomcat will be
203 available by visiting:
204
205 http://localhost:8080/
206
207(4.3) Further information about configuring and running Tomcat can be found in
208 the documentation included here, as well as on the Tomcat web site:
209
210 http://tomcat.apache.org/
211
212
213(5) Shut Down Tomcat
214
215(5.1) Tomcat can be shut down by executing one of the following commands:
216
217 On Windows:
218
219 %CATALINA_HOME%\bin\shutdown.bat
220
221 or
222
223 %CATALINA_HOME%\bin\catalina.bat stop
224
225 On *nix:
226
227 $CATALINA_HOME/bin/shutdown.sh
228
229 or
230
231 $CATALINA_HOME/bin/catalina.sh stop
232
233==================================================
234Advanced Configuration - Multiple Tomcat Instances
235==================================================
236
237In many circumstances, it is desirable to have a single copy of a Tomcat
238binary distribution shared among multiple users on the same server. To make
239this possible, you can set the CATALINA_BASE environment variable to the
240directory that contains the files for your 'personal' Tomcat instance.
241
242When running with a separate CATALINA_HOME and CATALINA_BASE, the files
243and directories are split as following:
244
245In CATALINA_BASE:
246
247 * bin - Only the following files:
248
249 * setenv.sh (*nix) or setenv.bat (Windows),
250 * tomcat-juli.jar
251
252 The setenv scripts were described above. The tomcat-juli library
253 is documented in the Logging chapter in the User Guide.
254
255 * conf - Server configuration files (including server.xml)
256
257 * lib - Libraries and classes, as explained below
258
259 * logs - Log and output files
260
261 * webapps - Automatically loaded web applications
262
263 * work - Temporary working directories for web applications
264
265 * temp - Directory used by the JVM for temporary files (java.io.tmpdir)
266
267
268In CATALINA_HOME:
269
270 * bin - Startup and shutdown scripts
271
272 The following files will be used only if they are absent in
273 CATALINA_BASE/bin:
274
275 setenv.sh (*nix), setenv.bat (Windows), tomcat-juli.jar
276
277 * lib - Libraries and classes, as explained below
278
279 * endorsed - Libraries that override standard "Endorsed Standards"
280 libraries provided by JRE. See Classloading documentation
281 in the User Guide for details.
282
283 By default this "endorsed" directory is absent.
284
285In the default configuration the JAR libraries and classes both in
286CATALINA_BASE/lib and in CATALINA_HOME/lib will be added to the common
287classpath, but the ones in CATALINA_BASE will be added first and thus will
288be searched first.
289
290The idea is that you may leave the standard Tomcat libraries in
291CATALINA_HOME/lib and add other ones such as database drivers into
292CATALINA_BASE/lib.
293
294In general it is advised to never share libraries between web applications,
295but put them into WEB-INF/lib directories inside the applications. See
296Classloading documentation in the User Guide for details.
297
298
299It might be useful to note that the values of CATALINA_HOME and
300CATALINA_BASE can be referenced in the XML configuration files processed
301by Tomcat as ${catalina.home} and ${catalina.base} respectively.
302
303For example, the standard manager web application can be kept in
304CATALINA_HOME/webapps/manager and loaded into CATALINA_BASE by using
305the following trick:
306
307 * Copy the CATALINA_HOME/webapps/manager/META-INF/context.xml
308 file as CATALINA_BASE/conf/Catalina/localhost/manager.xml
309
310 * Add docBase attribute as shown below.
311
312The file will look like the following:
313
314 <?xml version="1.0" encoding="UTF-8"?>
315 <Context docBase="${catalina.home}/webapps/manager"
316 antiResourceLocking="false" privileged="true" >
317 <Valve className="org.apache.catalina.valves.RemoteAddrValve"
318 allow="127\.0\.0\.1" />
319 </Context>
320
321See Deployer chapter in User Guide and Context and Host chapters in the
322Configuration Reference for more information on contexts and web
323application deployment.
324
325
326================
327Troubleshooting
328================
329
330There are only really 2 things likely to go wrong during the stand-alone
331Tomcat install:
332
333(1) The most common hiccup is when another web server (or any process for that
334 matter) has laid claim to port 8080. This is the default HTTP port that
335 Tomcat attempts to bind to at startup. To change this, open the file:
336
337 $CATALINA_HOME/conf/server.xml
338
339 and search for '8080'. Change it to a port that isn't in use, and is
340 greater than 1024, as ports less than or equal to 1024 require superuser
341 access to bind under UNIX.
342
343 Restart Tomcat and you're in business. Be sure that you replace the "8080"
344 in the URL you're using to access Tomcat. For example, if you change the
345 port to 1977, you would request the URL http://localhost:1977/ in your
346 browser.
347
348(2) The 'localhost' machine isn't found. This could happen if you're behind a
349 proxy. If that's the case, make sure the proxy configuration for your
350 browser knows that you shouldn't be going through the proxy to access the
351 "localhost".
352
353 In Firefox, this is under Tools/Preferences -> Advanced/Network ->
354 Connection -> Settings..., and in Internet Explorer it is Tools ->
355 Internet Options -> Connections -> LAN Settings.
356
357
358====================
359Optional Components
360====================
361
362The following optional components may be included with the Apache Tomcat binary
363distribution. If they are not included, you can install them separately.
364
365 1. Apache Tomcat Native library
366
367 2. Apache Commons Daemon service launcher
368
369Both of them are implemented in C language and as such have to be compiled
370into binary code. The binary code will be specific for a platform and CPU
371architecture and it must match the Java Runtime Environment executables
372that will be used to launch Tomcat.
373
374The Windows-specific binary distributions of Apache Tomcat include binary
375files for these components. On other platforms you would have to look for
376binary versions elsewhere or compile them yourself.
377
378If you are new to Tomcat, do not bother with these components to start with.
379If you do use them, do not forget to read their documentation.
380
381
382Apache Tomcat Native library
383-----------------------------
384
385It is a library that allows to use the "Apr" variant of HTTP and AJP
386protocol connectors in Apache Tomcat. It is built around OpenSSL and Apache
387Portable Runtime (APR) libraries. Those are the same libraries as used by
388Apache HTTPD Server project.
389
390This feature was especially important in the old days when Java performance
391was poor. It is less important nowadays, but it is still used and respected
392by many. See Tomcat documentation for more details.
393
394For further reading:
395
396 - Apache Tomcat documentation
397
398 * Documentation for APR/Native library in the Tomcat User's Guide
399
400 http://tomcat.apache.org/tomcat-7.0-doc/apr.html
401
402 * Documentation for the HTTP and AJP protocol connectors in the Tomcat
403 Configuration Reference
404
405 http://tomcat.apache.org/tomcat-7.0-doc/config/http.html
406
407 http://tomcat.apache.org/tomcat-7.0-doc/config/ajp.html
408
409 - Apache Tomcat Native project home
410
411 http://tomcat.apache.org/native-doc/
412
413 - Other projects
414
415 * OpenSSL
416
417 http://openssl.org/
418
419 * Apache Portable Runtime
420
421 http://apr.apache.org/
422
423 * Apache HTTP Server
424
425 http://httpd.apache.org/
426
427To disable Apache Tomcat Native library:
428
429 - To disable Apache Tomcat Native library when it is installed, or
430 - To remove the warning that is logged during Tomcat startup when the
431 library is not installed:
432
433 Edit the "conf/server.xml" file and remove "AprLifecycleListener" from
434 it.
435
436The binary file of Apache Tomcat Native library is usually named
437
438 - "tcnative-1.dll" on Windows
439 - "libtcnative-1.so" on *nix systems
440
441
442Apache Commons Daemon
443----------------------
444
445Apache Commons Daemon project provides wrappers that can be used to
446install Apache Tomcat as a service on Windows or as a daemon on *nix
447systems.
448
449The Windows-specific implementation of Apache Commons Daemon is called
450"procrun". The *nix-specific one is called "jsvc".
451
452For further reading:
453
454 - Apache Commons Daemon project
455
456 http://commons.apache.org/daemon/
457
458 - Apache Tomcat documentation
459
460 * Installing Apache Tomcat
461
462 http://tomcat.apache.org/tomcat-7.0-doc/setup.html
463
464 * Windows service HOW-TO
465
466 http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html
467
468The binary files of Apache Commons Daemon in Apache Tomcat distributions
469for Windows are named:
470
471 - "tomcat7.exe"
472 - "tomcat7w.exe"
473
474These files are renamed copies of "prunsrv.exe" and "prunmgr.exe" from
475Apache Commons Daemon distribution. The file names have a meaning: they are
476used as the service name to register the service in Windows, as well as the
477key name to store distinct configuration for this installation of
478"procrun". If you would like to install several instances of Tomcat 7.0
479in parallel, you have to further rename those files, using the same naming
480scheme.