Tuesday, 1 April 2014

Tomcat (installation and use)

Installation on Linux

  1. Download the last available distribution from:  http://tomcat.apache.org/ In my case, I downloaded the package: apache-tomcat-8.0.5.tar.gz
  2. Uncompress it it will create a folder apache-tomcat-8.0.5 where it will be the necessary components.
  3. Enter into the bin folder inside the Apache folder and you will see the available services to start and shutdown the server.
  4. Take into account that Apache tomcat will need java installed in the system and called from the system variable JAVA_HOME or JRE_HOME in order to start, so install it if you don't have it.
  5. That's all

Using it
  1. If you want to start, just run the script startup.sh : $CATALINA_BASE/apache-tomcat-8.0.5/bin$ sh startup.sh----------
    sheila@tux:~/Programs/apache-tomcat-8.0.5/bin$ sh startup.sh
    Using CATALINA_BASE:   /home/sheila/Programs/apache-tomcat-8.0.5
    Using CATALINA_HOME:   /home/sheila/Programs/apache-tomcat-8.0.5
    Using CATALINA_TMPDIR: /home/sheila/Programs/apache-tomcat-8.0.5/temp
    Using JRE_HOME:        /usr/java
    Using CLASSPATH:       /home/sheila/Programs/apache-tomcat-8.0.5/bin/bootstrap.jar:/home/sheila/Programs/apache-tomcat-8.0.5/bin/tomcat-juli.jar
    Tomcat started.---------------------------
    *** As you can see, when starting the server (by running startup), it will create other variables that it needs such as: CATALINA_BASE (allows to use several private configuration folders. It is useful when you want to have a single copy of Tomcat distribution shared among multiple users on the same server, each one would have their own configuration files and webapps), CATALINA_HOME (home of your Apache installation), etc. 
  2. To test the web server, you can type (http://localhost:8080/) on your browser and you will see and initial webpage from tomcat.
  3. Finally, if you want to stop the service, you can run the service: ...$sh shutdown.sh 

Creating users

In order to run your own web application, you will need to add have manager permissions.
To do more than just seeing the tomcat initial webpage, such as see current projects, create projects, deploy the, etc, you will need to have a user.
Users are saved in the file $CATALINA_BASE/conf/tomcat-users.xml.
It will be different configuration files for each different  $CATALINA_BASE-

Is a xml files such as this:


You can edit such file in order to allow users access.
Roles:  Users have rolls that will give them permissions to do different things.
- tomcat
- manager-gui
- manager-script
- admin
- etc

Depending on their role, users can  see projects or create project for example, among other functionalities.

Creating and Deploying applications
When you try to enter to the admin view (By clicking in the Manager App button or entering into http://localhost:8080/manager/html), it will ask you for a user and password. Enter them and you will be able to see another view containing the deployed projects.
Each project represents a folder inside the $CATALINA_BASE/webapps/ folder

When your user have enough permission, you can deploy new applications:

Way 1: Copy a folder containing your web project into the $CATALINA_BASE/webapps/ folder and it will automatically be deployed.

Way 2: Enter into the  Manager view and go to the "WAR file to deploy" part and browse to find the location of your folder and then click Deploy

If you don't have it installed, you can add it by Right-clicking on the servers and selecting : "Add Server"-Apache tomcat-next

You will see the following window:

Enter your server location (place where you uncompressed the dowloaded file).
Then you can choose to create a new Configuration folder (catalina_base).
Finally, you can create a user or use and existing one.  It will add that user to the conf/tomcat-users.xml inside your own catalina_base folder.

Example: I created an specific CATALINA_BASE for netbeans called: CONFIGNetbeans inside my uncompressed and installed tomcat. The specific config files for netbeans are inside that folder as we can see in the right part of the following image.