- Apache Tomcat 7 Essentials
- Tanuj Khare
- 3333字
- 2021-08-20 15:35:10
Installation of Tomcat 7
In the previous section, we have discussed the new enhancements in Apache Tomcat 7. Now, it's time to move on to the Tomcat installation.
How to download the Tomcat software
Perform the following steps to download the software:
- Before we start the installation of Apache Tomcat 7 software, the first thing that comes to mind is where can you download the software from and also how much does the license cost? By default, Apache comes with Apache License, Version 2.0 ,which is compatible to GPL (General Public License). In simple terms, it is free of cost! For more information on licenses, you can visit http://www.apache.org/licenses/. Now, the second problem is how to download the software.
- It is always recommended to download the software from its official site,
http://tomcat.apache.org/download-70.cgi
. By default, on http://tomcat.apache.org/, we get the latest stable version of Tomcat package and we have to download the package based on the operating system, where we want to install it.

Once the download is complete, then you have to do the integrity check for the downloaded software using the MD5 checksum.
Following is the process to perform the integrity check using the MD5 checksum:
- Download the MD5 checksum from the website apache.org. The MD5 check sum is integrated with every package we download. The previous screenshot shows the packages which are available in MD5, and by clicking on md5 on the website, we can compare the checksum generated in our system with the value given on the site.
- Run the following command to generate the checksum for the downloaded software. See the following screenshot:
[root@localhost opt]# cksum apache-tomcat-7.0.12.zip
Tomcat comes with different packages for installation such as binary, source, and RPM. Based on the requirement, the package should be taken from the official site. Let's have a brief discussion on which package should be implemented in real time and why.
It comes with a pre-set library and customized configuration which are implemented and tested as per industry standards. A few advantages of using the binary package are:
- It is a standard package that suits most of the real-time environments
- In a non-DOS environment (such as Linux, UNIX, and so on), we can configure multiple Tomcat instances on a single OS
- It is path independent; we can configure Tomcat in any part of the OS based on our resources available (hardware)
RPM is defined as a system installer, which is developed and compiled on each OS independently. It has a pre-defined library, which will work only on the respective OS. A few advantages of using RPM are:
- It does not require installation of any dependent libraries for the package
- RPM is built with the shared libraries for the respective OS
- It does not need to configure separate startup services
The only disadvantage is, we cannot configure multiple instances in a single operating system and it has predefined paths.
You can customize the installation based on your requirements using the source package. Suppose you want to customize during installation of the software, it can be done in this package.
- Customization of Tomcat can be done very effectively (only required services are installed)
- In a non-DOS environment (such as Linux, UNIX, and so on), we can configure multiple Tomcat instances on a single OS
- It is path independent; we can configure Tomcat in any part of the OS based on our resources available (hardware)
- In a production environment, it's always recommended to use the source or binary instead of the RPM
Prerequisites for the Tomcat 7 installation
Before we begin with the Apache Tomcat 7 installation, we have to configure the prerequisites and they are very important for the Tomcat 7 installation to start. Following are the prerequisites mentioned for Apache Tomcat 7:
- Java SE 1.6 or later
- Configuration of the OS environment variables
Java has been developed by many vendors. Based on the application requirement and type of architecture, different JVMs are used by various applications. Common JDK vendors are IBM, HP, Sun, OpenJDK, and so on. Sun holds a major stake in IT industries. JDK is widely used and accepted across various IT industries.
JDK packages are available for each OS and can be compiled on any system using a common set of libraries. These packages are easily available on the Internet or already integrated with different OS vendors.
JDK/JRE comes in 32 bit and 64 bit editions, so we can use it based on the application requirement. Some of the performance characteristics of the 64 bit versus 32 bit Virtual Machine (VM) are:
- The benefits of using 64 bit are being able to address larger amounts of memory which comes with a small performance loss in 64 bit VMs, versus running the same application on a 32 bit VM
- You can allocate more than 4 GB to JVM for memory intensive applications
In this topic, we will discuss the steps performed during installation of Java on Linux:
- Download the JDK from the Oracle site on the Linux system.
Note
For more information about the version changes and releases, visit http://www.oracle.com/technetwork/java/javase/downloads/index.html.
We are doing the installation on the
/opt
partition of the hard drive and the Java version we are using is Java(TM) SE Runtime Environment (build 1.6.0_24-b07).- Once the download is complete, it will create the binary file in
/opt
(jdk-6u24-linux-i586.bin
).
- Once the download is complete, it will create the binary file in
- Change the permission of the package using the following command:
chmod 0755 jdk-6u24-linux-i586.bin
- Run the following command to install the JDK:
[root@localhost opt]# ./jdk-6u24-linux-i586.bin
- You will see an output similar to the following screenshot:
- During the installation, the binary will prompt for the acceptance of the agreement, then press Enter. See the following screenshot:
- After pressing Enter it will exit from the command prompt, as shown in the following screenshot:
- After the installation is complete, the binary will create the folder named
jdk1.6.0_24
in/opt
. If the folder is present in/opt
, that means the installation is successfully done. See the following screenshot:
Let's quickly go through the JDK directory structure, shown in the previous screenshot:
bin:
It contains the entire executable for the JDK for java, javac, jmap, and so on.jre:
It contains all the files necessary for Java to perform the function.lib:
As the name suggests, it's a library directory for the JDK.man:
This directory contains all the manual pages for Java (document directory).demo:
-This folder contains working examples of different utilities. These utilities can be directly used.sample:
This directory contains the code files for utilities provided in the demo directory.include:
It contains the header files for different functions used in Java.hdb:
It contains the entire component of the Derby Database. Derby is a pure Java relational database engine.
In this topic, we will discuss the steps performed during installation of Java in the Windows operating system:
- Download the JDK from the Oracle site on the Windows system from the following link: http://www.oracle.com/technetwork/java/javase/downloads/index.html.
- Once the download is complete,
jdk-6u24-windows-i586.exe
is created in the download location. - By double-clicking the
jdk-6u24-windows-i586.exe
file, installation of Java will begin. It will open a new pop-up window for installation. See the following screenshot: - By clicking Next on the window, it will take us to a new window where we can customize the JDK installation based on the requirement, as well as define the installation path of the JDK. In the current environment, we are installing Java on the default location.
- Check if the default path is
C:\Program Files\Java\jdk1.6.0_24
. - Check the field Installation type: Default.
- Once the installation is done, it will show the status as complete, similar to the following screenshot:
After the installation of Java on a different OS, it's now time to set the environment variables for Tomcat at the OS level. In order to run Tomcat, we have to define the JAVA_HOME
as an environment variable and set the path for Java so that it can be accessed from any partition of OS.
JAVA_HOME
is the JDK install directory, for example, C:\jdk6
. It is meant to be set as an environment variable and referenced in Windows batch files or Unix scripts. In Tomcat, JAVA_HOME
is defined in catalina.sh
under TOMCAT_HOME/bin
. The following screenshot shows the definition of JAVA_HOME
in Tomcat 7. Once you execute startup.sh
, it internally calls catalina.sh
and invokes JAVA_HOME
. In a production environment, it is always recommended to use the permanent environment variable.

The environment variable and path can be set in Windows by performing the following steps:
- Right-click on the My Computer icon on your desktop and then click Properties, as shown in the following screenshot:
- Click Advanced | Environment Variables.
- Under System Variables, click New.
- In the Variable name field, enter
JAVA_HOME
, as shown in the following screenshot: - In the Variable value field, enter the installation path of the Java Development Kit.
- Click OK.
- Click on Apply Changes.
After setting JAVA_HOME
, now it is time to add the Java path in the global path variable. Following is a detailed procedure, which needs to be followed for creating the global path variable in Windows:
- Right-click on the My Computer icon on your desktop and then click Properties.
- Click Advanced | Environment Variables.
- Under System Variables, click on Path.
- Edit the path and add the Java path in the end.
- In the Variable value field, enter the installation path of the Java Development Kit, as shown in the previous screenshot.
- Click OK.
- Click on Apply Changes.
The environment variable and path are set differently in Linux as compared to Windows. Perform the following steps to set the environment variable in Linux:
- Open the
.bash_profile
using the vi editor for the root user. - Add the following environment variable in the file. The following is the code snippet of
.bash_profile
. The highlighted code shows the declaration ofJAVA_HOME
andPATH. export
will add theJAVA_HOME
andPATH
to the system parameter for every user login.# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ];then . ~/.bashrc fi # User specific environment and start-up programs JAVA_HOME=/opt/jdk1.6.0_24 PATH=$JAVA_HOME/bin:$PATH:$HOME/bin export PATH JAVA_HOME unset USERNAME
- Save the
.bash_profile
using the:wq
command. - Once you have saved the
.bash_profile
, then you have to logout and re-log in to the environment to activate the changes using the following command:su - username su - root (as our user is root)
Also, you can run the env
command to verify the environment variables are configured properly, as shown in the following screenshot:

Now we have set the environment variable for Windows and Linux environments, but how can we verify whether the environment is set properly or not?
Before we start installation of Apache Tomcat 7, let's quickly verify the environment variable on both the OSes.
In the Windows environment, variables can be verified using the following command:
echo %VARIABLE_NAME%
For JAVA_HOME:
C:\Users\user>echo %JAVA_HOME% C:\Program Files\Java\jdk1.6.0_24
For PATH:
C:\Users\user>echo %PATH% C:\Program Files\PC Connectivity Solution\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\ Program Files\Broadcom\Broadcom 802.11\Driver; C:\Program Files\Java\jdk1.6.0_24\bin
In Linux, we can use the following command to verify the environment variables:
echo $VARIABLE_NAME
For JAVA_HOME:
[root@localhost ~]# echo $JAVA_HOME /opt/jdk1.6.0_24
For PATH:
[root@localhost ~]# echo $PATH /opt/jdk1.6.0_24/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/ sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
After verifying the environment variable on both the OSes, we are sure that JAVA_HOME
and PATH
are properly set in the environment. We have completed the prerequisites of installation of Apache Tomcat 7. Now, we can proceed with the installation of Apache Tomcat 7.
Installation of Apache Tomcat 7
Let's start the installation of Tomcat 7 on different OSes. The steps involved to install the software on Windows are discussed first, and then we move on to the Linux environment.
In this topic, we will discuss the steps involved during the software installation of Tomcat 7. Following are the steps:
- Download the latest stable version from the Tomcat official site, http://tomcat.apache.org/download-70.cgi. We are downloading the 32-bit/64-bit Windows Service Installer (pgp, md5). Once the download is complete, save it in the software folder.
- Double-click on
apache-tomcat-7.0.14.exe
. It will launch the setup wizard.Note
If you don't find the
exe
file along with the downloaded folder, download it using the link, http://apache.osuosl.org/tomcat/tomcat-7/v7.0.23/bin/. Save the file in theapache-tomcat
folder. - Then, click on Next button to continue, as shown in the following screenshot:
- An agreement pop-up is displayed. Click on I Agree. It means we agree to use Tomcat 7 as per the GPL license, as shown in the following screenshot:
- The following window shows us the different components we need to install:
- In the next step, we have to configure the username and password for the Tomcat Manager, as shown in the following screenshot. We have set the Username and Password to
admin
. Click on Next. - In the next window, it will pick up the Java version from the
JAVA_HOME
variable, if the variables are properly defined, as shown in the following screenshot: - The next window displays the installation path of Tomcat. By default, we use
C:\Program Files\Apache Software Foundation\Tomcat 7.0
. In case we want to change it, then we have to click on Browse and select the desired path. Click on Install, as shown in the following screenshot: - It's the final step of the Tomcat 7 installation. This will display the successful implementation of Tomcat, as shown in the following screenshot:
Installation of Tomcat 7 is quite simple in a Linux environment as compared to Windows. It can be done in just three steps:
- Download the latest stable version from Tomcat's official site http://tomcat.apache.org/download-70.cgi. Once the download is complete, save it in the
/opt
location. Unzip the Tomcat 7 source, that is,apache-tomcat-7.0.12.zip
using the following command:[root@localhost opt]# unzip apache-tomcat-7.0.12.zip
- After you unzip the
apache-tomcat-7.0.12.zip
, it will create the directory namedapache-tomcat-7.0.12
in theopt
directory. Go to thebin
directories ofapache-tomcat-7.0.12
using the following command:[root@localhost opt]# cd apache-tomcat-7.0.12/bin/
- Run the following command. If you fail to run the following command, then Tomcat services will not come up. By default, the package comes with read/write permissions, but no execution permissions are given to the package. We have to manually change the permissions:
[root@localhost bin]# chmod 0755 *.sh [root@localhost bin]# pwd /opt/apache-tomcat-7.0.12/bin
After this step, the installation of Tomcat is complete in Linux.
Startup and shutdown of Tomcat services
We have now completed the installation of Apache Tomcat on both the OSes. Now, it's time to start the services and verify the setup we have created up to now. So why waste time, let's rock and roll.
In Windows, we can start/stop the services using two methods:

- Apache monitor console: Tomcat comes with a very handy tool for administration, which is popularly known as the Apache monitoring console. It's very useful in managing the Tomcat instance (service recycle, enabling logs, and JVM configuration).The following screenshot shows the recycle process using the Tomcat monitoring console. To start/stop services, go to Start | Programs | Apache-Tomcat7 |apache-tomcat monitor Start/Stop.

The Linux startup process is completely different. Here, we have to run the startup/shutdown scripts manually to bring the services online. Let us start the services on Linux to verify the installation.
Before that, let's quickly verify the configuration. Tomcat 7 comes with different scripts, through which we will verify the complete installation. There is a very good script placed in the Tomcat bin
directory named as version.sh
, through which we can verify the complete Tomcat version and system information. Let's run the script using the following command:
[root@localhost bin]# ./version.sh Using CATALINA_BASE: /opt/apache-tomcat-7.0.12 Using CATALINA_HOME: /opt/apache-tomcat-7.0.12 Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.12/temp Using JRE_HOME: /opt/jdk1.6.0_24 Using CLASSPATH: /opt/apache-tomcat-7.0.12/bin/bootstrap.jar:/opt/apache-tomcat-7.0.12/bin/tomcat-juli.jar Server version: Apache Tomcat/7.0.12 Server built: Apr 1 2011 06:13:02 Server number: 7.0.12.0 OS Name: Linux OS Version: 2.6.18-8.el5 Architecture: i386 JVM Version: 1.6.0_24-b07 JVM Vendor: Sun Microsystems Inc.
There is one more script in the Tomcat bin
directory that is very useful. configtest.sh
is used to check any configuration changes in scripts. This script performs a quick configuration check on the system and finds the errors. Let's run the script using the following command:
[root@localhost bin]# ./configtest.sh Using CATALINA_BASE: /opt/apache-tomcat-7.0.12 Using CATALINA_HOME: /opt/apache-tomcat-7.0.12 Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.12/temp Using JRE_HOME: /opt/jdk1.6.0_24 Using CLASSPATH: /opt/apache-tomcat-7.0.12/bin/bootstrap.jar:/opt/apache-tomcat-7.0.12/bin/tomcat-juli.jar May 22, 2011 4:06:16 PM org.apache.coyote.AbstractProtocolHandler init INFO: Initializing ProtocolHandler ["http-bio-8080"] May 22, 2011 4:06:16 PM org.apache.coyote.AbstractProtocolHandler init INFO: Initializing ProtocolHandler ["ajp-bio-8009"] May 22, 2011 4:06:16 PM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 1401 ms
After doing the configuration check, start the Tomcat services. The Tomcat services can be started using the startup.sh
in the bin
directory.
To start the Tomcat services, you have to perform the following mentioned steps:
- The first step is to change the directory from the current location to the Tomcat directory.
[root@localhost bin]# cd /opt/apache-tomcat-7.0.12/bin/
- In the
bin
directory, we will find the entire executable for Tomcat. To start the services, we have to use the following command. Once you execute the startup command, it will display the parameters which are essential for booting Tomcat. Some of them areCATALINA_BASE, CATALINA_HOME, JRE_HOME
, and so on.[root@localhost bin]# ./startup.sh Using CATALINA_BASE: /opt/apache-tomcat-7.0.12 Using CATALINA_HOME: /opt/apache-tomcat-7.0.12 Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.12/temp Using JRE_HOME: /opt/jdk1.6.0_24 Using CLASSPATH: /opt/apache-tomcat- 7.0.12/bin/bootstrap.jar:/opt/apache-tomcat-7.0.12/bin/ tomcat-juli.jar
A Tomcat shutdown script is also available in the bin
directory named as ./shutdown.sh
. Let's execute the script to know the output. The details are as follows:
[root@localhost bin]# cd /opt/apache-tomcat-7.0.12/bin/ [root@localhost bin]# ./shutdown.sh Using CATALINA_BASE: /opt/apache-tomcat-7.0.12 Using CATALINA_HOME: /opt/apache-tomcat-7.0.12 Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.12/temp Using JRE_HOME: /opt/jdk1.6.0_24 Using CLASSPATH: /opt/apache-tomcat- 7.0.12/bin/bootstrap.jar:/opt/apache-tomcat-7.0.12/bin/tomcat-juli.jar
Verification of Tomcat status
Once we have executed the startup scripts, the next step is the verification of the Tomcat services, to check whether services are coming up fine or not. By default, Tomcat runs on HTTP port 8080 and can be accessed on the web browser using the URL, http://localhost:8080
. We then find the Tomcat welcome page, which shows that Tomcat is installed correctly and running fine in the environment, as shown in the following screenshot:

Once the welcome page for Tomcat 7 is displayed, we can verify the server status by clicking on Server Status.
It will prompt for the user ID/password. Remember, we have created a user admin that the user ID will be used here for access, as shown in the following screenshot:
