You are on page 1of 4

2/28/2014

Apache Tomcat

Apache Tomcat
Apache Tomcat is a web container that allows you to serve Java Servlets and JSP (Java Server Pages) web applications. The Tomcat 6.0 packages in Ubuntu support two different ways of running Tomcat. You can install them as a classic unique system-wide instance, that will be started at boot time will run as the tomcat6 unprivileged user. But you can also deploy private instances that will run with your own user rights, and that you should start and stop by yourself. This second way is particularly useful in a development server context where multiple users need to test on their own private Tomcat instances. System-wide installation Configuration Using Tomcat standard webapps Using private instances References

System-wide installation
To install the Tomcat server, you can enter the following command in the terminal prompt: s u d oa p t g e ti n s t a l lt o m c a t 6 This will install a Tomcat server with just a default ROOT webapp that displays a minimal "It works" page by default.

Configuration
Tomcat configuration files can be found in / e t c / t o m c a t 6 . Only a few common configuration tweaks will be described here, please see Tomcat 6.0 documentation for more.

Changing default ports


By default Tomcat 6.0 runs a HTTP connector on port 8080 and an AJP connector on port 8009. You might want to change those default ports to avoid conflict with another server on the system. This is done by changing the following lines in / e t c / t o m c a t 6 / s e r v e r . x m l : < C o n n e c t o rp o r t = " 8 0 8 0 "p r o t o c o l = " H T T P / 1 . 1 " c o n n e c t i o n T i m e o u t = " 2 0 0 0 0 " r e d i r e c t P o r t = " 8 4 4 3 "/ > . . . < C o n n e c t o rp o r t = " 8 0 0 9 "p r o t o c o l = " A J P / 1 . 3 "r e d i r e c t P o r t = " 8 4 4 3 "/ >

Changing JVM used


By default Tomcat will run preferably with OpenJDK-6, then try Sun's JVM, then try some other JVMs. If you have
https://help.ubuntu.com/12.04/serverguide/tomcat.html 1/4

2/28/2014

Apache Tomcat

various JVMs installed, you can set which should be used by setting JAVA_HOME in / e t c / d e f a u l t / t o m c a t 6 : J A V A _ H O M E = / u s r / l i b / j v m / j a v a 6 s u n

Declaring users and roles


Usernames, passwords and roles (groups) can be defined centrally in a Servlet container. In Tomcat 6.0 this is done in the/ e t c / t o m c a t 6 / t o m c a t u s e r s . x m lfile: < r o l er o l e n a m e = " a d m i n " / > < u s e ru s e r n a m e = " t o m c a t "p a s s w o r d = " s 3 c r e t "r o l e s = " a d m i n " / >

Using Tomcat standard webapps


Tomcat is shipped with webapps that you can install for documentation, administration or demo purposes.

Tomcat documentation
The tomcat6-docs package contains Tomcat 6.0 documentation, packaged as a webapp that you can access by default at http://yourserver:8080/docs. You can install it by entering the following command in the terminal prompt: s u d oa p t g e ti n s t a l lt o m c a t 6 d o c s

Tomcat administration webapps


The tomcat6-admin package contains two webapps that can be used to administer the Tomcat server using a web interface. You can install them by entering the following command in the terminal prompt: s u d oa p t g e ti n s t a l lt o m c a t 6 a d m i n The first one is the manager webapp, which you can access by default at http://yourserver:8080/manager/html. It is primarily used to get server status and restart webapps. Access to the manager application is protected by default: you need to define a user with the role "manager" in/ e t c / t o m c a t 6 / t o m c a t u s e r s . x m lbefore you can access it. The second one is the host-manager webapp, which you can access by default at http://yourserver:8080/hostmanager/html. It can be used to create virtual hosts dynamically. Access to the host-manager application is also protected by default: you need to define a user with the role "admin" in/ e t c / t o m c a t 6 / t o m c a t u s e r s . x m lbefore you can access it. For security reasons, the tomcat6 user cannot write to the / e t c / t o m c a t 6directory by default. Some features in these admin webapps (application deployment, virtual host creation) need write access to that directory. If you want to use these features execute the following, to give users in the tomcat6 group the necessary rights: s u d oc h g r pRt o m c a t 6/ e t c / t o m c a t 6
https://help.ubuntu.com/12.04/serverguide/tomcat.html 2/4

2/28/2014

Apache Tomcat

s u d oc h m o dRg + w/ e t c / t o m c a t 6

Tomcat examples webapps


The tomcat6-examples package contains two webapps that can be used to test or demonstrate Servlets and JSP features, which you can access them by default at http://yourserver:8080/examples. You can install them by entering the following command in the terminal prompt: s u d oa p t g e ti n s t a l lt o m c a t 6 e x a m p l e s

Using private instances


Tomcat is heavily used in development and testing scenarios where using a single system-wide instance doesn't meet the requirements of multiple users on a single system. The Tomcat 6.0 packages in Ubuntu come with tools to help deploy your own user-oriented instances, allowing every user on a system to run (without root rights) separate private instances while still using the system-installed libraries. It is possible to run the system-wide instance and the private instances in parallel, as long as they do not use the same TCP ports.

Installing private instance support


You can install everything necessary to run private instances by entering the following command in the terminal prompt: s u d oa p t g e ti n s t a l lt o m c a t 6 u s e r

Creating a private instance


You can create a private instance directory by entering the following command in the terminal prompt: t o m c a t 6 i n s t a n c e c r e a t em y i n s t a n c e This will create a new m y i n s t a n c edirectory with all the necessary subdirectories and scripts. You can for example install your common libraries in the l i b /subdirectory and deploy your webapps in the w e b a p p s /subdirectory. No webapps are deployed by default.

Configuring your private instance


You will find the classic Tomcat configuration files for your private instance in the c o n f /subdirectory. You should for example certainly edit thec o n f / s e r v e r . x m lfile to change the default ports used by your private Tomcat instance to avoid conflict with other instances that might be running.

Starting/stopping your private instance


You can start your private instance by entering the following command in the terminal prompt (supposing your
https://help.ubuntu.com/12.04/serverguide/tomcat.html 3/4

2/28/2014

Apache Tomcat

instance is located in the m y i n s t a n c edirectory): m y i n s t a n c e / b i n / s t a r t u p . s h You should check the l o g s /subdirectory for any error. If you have a java.net.BindException: Address already in use<null>:8080 error, it means that the port you're using is already taken and that you should change it. You can stop your instance by entering the following command in the terminal prompt (supposing your instance is located in the m y i n s t a n c e directory): m y i n s t a n c e / b i n / s h u t d o w n . s h

https://help.ubuntu.com/12.04/serverguide/tomcat.html

4/4