Sunday, February 1, 2009

Installing Apache Tomcat On Linux And Windows

If you want to learn JSP (Java Server Page) or create a website with JSP programming language, you need to install a web server named Apache Tomcat. Apache Tomcat can be installed both in Linux and Windows operating system.

Preparation

Before you install Apache Tomcat, you need to install one of JRE (Java Runtime Environment) or JDK (Java Development Kit). You can download the latest version of JRE or JDK from http://java.sun.com. If you are using Windows, you need to download the one for Windows platform, and if you are using Linux, you have to choose the one for Linux platform.

Installing JRE or JDK on Windows is easy, just double click the installer and follow the instruction. Installing on Linux is also easy. Just execute this command as root. I assume you save your JDK or JRE installer in /usr/local.

# cd /usr/local # ./jdk1.6.0_01.bin

In this tutorial, I used JDK 1.5 for Windows with C:\Program Files\Java\jdk1.5.0_06 as its installation directory and JDK 1.6 for Linux with /usr/local/java as its installation directory.

After JRE or JDK is installed, you need to download the Apache Tomcat from http://tomcat.apache.org/download-60.cgi. The version of Apache Tomcat used in this example is 6.0. Then, choose the binary version in .tar.gz or .zip format. In this example I choose the .tar.gz format.


The good news is, the binary file that you download can be installed on Windows or Linux. So, you don't have to download twice if you want to try installing it on those both platforms. That's right because Apache Tomcat is based on Java, that's why we need the JRE.


Installation On Windows

The installation of Apache Tomcat on Windows has these following steps.

  1. Extract the Apache Tomcat binary file to C: or another location you like. After that, you will get the folder named apache-tomcat-xxx depending on your Apache Tomcat version. Then, rename it to easier name like apache-tomcat or another name if necessary.
  2. Set the JAVA_HOME environment variable. This system variable is needed to tell the Apache Tomcat where the location of your JRE. So, open your Windows Control Panel, choose System then click the Advance tab. Click the Environment Variables button, then click the New button in System Variabels frame. After that, a small window will appear. Write JAVA_HOME in the Variable name TextBox. Then, write the location of your JDK or JRE installation in the Variable value TextBox as you can see in the picture below.

  3. Restart your computer to make the change take effect
  4. Now, start your Apache Tomcat by executing the startup.bat file inside the bin directory of you Apache Tomcat installation directory. When you start your Apache Tomcat, you will see this window appear.


  5. Access http://localhost:8080. If you see the Apache Tomcat welcome page that means you have successfully installed Apache Tomcat and ready to use JSP.
  6. If you want to shutdown the Apache Tomcat, execute shutdown.bat file which is located in the same folder with the startup.bat file.

Installation On Linux

These are the installation steps on Linux operating system. You also need to login as root.

  1. Extract your the Apache Tomcat binary file on /usr/local. I also assume you put your Apache Tomcat binary file on /tmp folder. Then rename the apache-tomcat-xxx folder with an easier name.
    # cd /usr/local
    # tar -xvzf /tmp/apache-tomcat-xxx.tar.gz
    # mv apache-tomcat-xxx apache-tomcat

  2. Create the setenv.sh file using the vi editor inside the bin folder. Press I or INSERT to enter the insert mode.
    # cd apache-tomcat/bin # vi setenv.sh

    This file is used to tell Apache Tomcat about the location of your JRE or JDK. The content of this file is like this.
    #!/bin/sh
    #-----------------
    # Set Environment
    #-----------------
    JAVA_HOME="/usr/local/java"; export JAVA_HOME

    Please replace the "/usr/local/java" with your JRE or JDK installation path.
  3. Save the file by pressing ESC : w q. Then make the file executable.
    # chmod 755 setenv.sh

  4. Start your Apache Tomcat by executing the startup.sh file.
    # ./startup.sh

  5. Access http://localhost:8080 from your web browser. If you see this page, that means you have successfully installed Apache Tomcat.

  6. To stop Apache Tomcat, simply execute the shutdown.sh file.
    # ./shutdown.sh

No comments: