How to Install Apache Tomcat With IIS6

download How to Install Apache Tomcat With IIS6

of 17

Transcript of How to Install Apache Tomcat With IIS6

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    1/17

    How To Integrate IIS6 and Apache Tomcat

    By Glenn Barnas / InnoTech Consulting Groupwww.innotechcg.com

    This is a step by step guide to installing Apache Tomcat 6.x on systems running IIS 6.0. The process

    should work on other combinations of IIS and Tomcat with minimal adjustments.

    System Configuration:

    For this installation, I used the latest versions of software available during May, 2007.

    Windows Server 2003 Standard Edition (no change for Enterprise) w/ SP-2 Internet Information Services (IIS) 6.0 Sun Java Runtime JRE 6.0 Update 1 Apache Jakarta Tomcat version 6.0.13 The isapi_redirect.dll version 1.2.22

    Install the Java Runtime Environment

    Launch the JRE installer. When prompted, choose a custom installation. I disable the browser

    integration, media support, and change the install path as shown. Click Next to start the install.

    Fig. 1Java JRE Setup

    http://www.innotechcg.com/http://www.innotechcg.com/http://www.innotechcg.com/
  • 7/31/2019 How to Install Apache Tomcat With IIS6

    2/17

    Fig. 2JRE Installation Complete

    I prefer to run an automated install for thisthe command line I used is shown below. You will need

    to reflect the correct JRE.exe file name, and possibly change the location of the log file.

    jre-6u1-windows-i586-p.exe /s ADDLOCAL=jrecore INSTALLDIR=%ProgramFiles%\Java\Jre IEXPLORER=0MOZILLA=0 JAVAUPDATE=0 REBOOT=Suppress WEBSTARTICON=0 /L %SYSTEMDRIVE%\Temp\JRE6setup.log

    If you use the automated install command, Java Automatic Updates are disabled. This is our

    preferred setting on servers, so we can control the what and when updating process. If youmanually installed Java, you can disable the automatic updates in the Java control panel.

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    3/17

    Configuration of Java and TomcatBoth Java and Tomcat need environment variables defined so applications can locate the folders that

    they are installed to. Open the System Properties dialog box and select the Advanced tab. (right-click

    My Computer and choose Properties) Click the Environment Variables button at the bottom of

    the dialog box.

    Fig. 3System Properties Dialog Box Fig. 4Environment Variables Dialog Box

    Click New on the System (lower) section of the Environment Variables dialog box. The

    applications will not work with User variables! When prompted, add a new system variable calledJAVA_HOMESet the value to the location where Java was installed. We consider Java a system

    application, so it is installed to C:\Program Files.

    Fig. 5Setting the Java Environment Variable

    While we are here, define the CATALINA_HOME system variable that Tomcat requires. Specify

    the path where you have decided to install Tomcat. We consider this an external application, so it

    is installed to the application driveE:\Apps\Tomcat in this case.

    Fig. 6Setting the Tomcat Environment Variable

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    4/17

    Installing TomcatWe are ready to begin the Tomcat installation at this point. Since Tomcat is designed to work with

    several different web servers, it is not delivered with any components or configuration files for

    specific web servers. Since this is the case, and IIS requires specific components and configurationfiles, I prefer to put them in place before the installation of Tomcat.

    Preparation

    Having decided to install Tomcat to E:\Apps\Tomcat, start by creating some of the folders thatTomcat will use. We need to place two .properties files into the /conf folder, and put the

    isapi_redirect.dll file into the /bin/win32/i386 folder. The location of the redirector DLL is up toyou, but this is the standard location used by Tomcat in the past. In the steps below, refers to the folder where Tomcat is installed, as specified in the CATALINA_HOME

    environment variable you defined earlier.

    Create the \conf folder Create the \bin\win32\i386 folder Copy the isapi_redirect.dll file to \bin\win32\i386 Create a workers.properties file in the \conf folder. Copy the following lines

    to that file to create a default configuration for testing.

    # Define 1 real worker using ajp13worker.list=worker1# Set properties for worker1 (ajp13)worker.worker1.type=ajp13worker.worker1.host=localhostworker.worker1.port=8009

    Create a uriworkermap.properties file in the \conf folder. Copy the followinglines to that file to create a default configuration for testing. This assumes that the root of the

    Tomcat examples folder is called examples. This is the default installation method for this

    version.

    /examples/*=worker1

    /examples/*.jsp=worker1/examples/servlet/*=worker1

    Copy the following lines to a file called isapi.reg, and merge this registry file into yourservers system registry. Be sure to edit the 3 path definitions to reflect your

    configuration before merging the registry file!

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector]

    [HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0]"extension_uri"="/jakarta/isapi_redirect.dll""log_file"="E:\\Apps\\Tomcat\\logs\\isapi.log""log_level"="debug""worker_file"="E:\\Apps\\Tomcat\\conf\\workers.properties"

    "worker_mount_file"="E:\\Apps\\Tomcat\\conf\\uriworkermap.properties" You will want to edit the .properties files after the basic configuration is working to reflect yourproduction environment. These are simply sample files to illustrate the relationship between workers

    and URIs. These files will be reviewed in some detail at the end of this document.

    Launch the Tomcat Installer

    Run the apache-tomcat-6.0.13.execommand to start the installation process. Click next on the

    splash screen, and I Agree on the license agreement screen.

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    5/17

    When prompted to choose components, select Full for the first Tomcat installation so you haveaccess to all of the example .JSP and Servelet files. For production installations, choose Custom,select Tomcat and all its sub-items, and de-select everything else.

    Fig. 7 - Tomcat Setup Dialog for Custom Install

    After choosing the components appropriate for your installation, you can select the install location.Browse to the folder you specified in CATALINA_HOME. As I mentioned earlier, we prefer to not

    install application software on the drive containing the O/S.

    Fig. 8Define the installation folder

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    6/17

    Define the HTTP/1.1 Connector Port and Admin ID/Password on the next screen. The ConnectorPort is the TCP/IP port that the Tomcat service will be listening on. If no other web server is

    utilizing this port, accept the default of 8080, otherwise choose an available port.

    Define an appropriate user name and password for web-based Tomcat administration. Be sure to

    follow your companys guidelines for secure passwords on production servers.

    Fig. 9Configuring the Tomcat Connector port and Admin password

    The installer will locate your JRE pathchange it only if necessary.

    Fig. 10Configuring the JVM/JRE path

    Click Install to complete the Tomcat installation process. When the installation completes, you willbe presented with the opportunity to start the Tomcat service and view the Readme file. It is OK to

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    7/17

    start the service at this time (since we already put the needed configuration files in place), and it is agood idea to review the Readme file.

    Fig. 11Tomcat Installation is complete

    Verify that the installation has added a new service called Apache Tomcat (Tomcat6). Check that

    it is running, and that it is set to start automatically.

    Fig. 12The Apache Tomcat service

    Test the Tomcat Installation

    On the system where you installed Tomcat, launch a web browser and connect tohttp://localhost:8080. You should see the Tomcat home page display.

    http://localhost:8080/http://localhost:8080/http://localhost:8080/
  • 7/31/2019 How to Install Apache Tomcat With IIS6

    8/17

    Fig. 13Default Tomcat web page on port 8080

    You should take a few moments to test the JSP and Servlet examples to verify that everything is

    functioning properly.

    Fig. 14Testing the Tomcat installation

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    9/17

    Integrating IIS and TomcatSince we adhere to strict Best Practice standards for IIS installations, I want to explain our

    configuration before continuing. We do not use the inetpub folder structure at all. We instead create

    a webfiles folder on the application drive. In the webfiles folder, we create a subfolder for each web

    instance, including the Default instance. Each of these instance subfolders has a web subfolder thatbecomes the root of the web instance. This provides some physical isolation between multiple web

    instances on a single system. It also permits folders to be created within a web application that are

    not directly part of the web structure.

    Preparation

    Before beginning the IIS/Tomcat integration, I prepared the IIS web server to have a Default web

    instance, and an application instance that would employ Tomcat. You can see this configuration in

    Figs. 15 and 16. I placed simple default.htm files in the root of each web instance that clearly

    identified the web instance that was returning the page. The home page message reported that theDefault or Primary Production instance had replied. These pages helped in troubleshooting during

    the integration process.

    Fig. 15Web Site Configuration

    Fig 16Web Folder Structure

    You do not have to follow this structure for the IIS/Tomcat integration to work. This information is

    presented so that you can make sense of the remaining configuration settings and adapt them to yourenvironment. In many cases, you will need to point to web applications outside of the default web

    data structure!

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    10/17

    Fig 17Sample Home Page to Identify Web Instance

    IIS Configuration jakarta Virtual Directory

    All of the following configurations will take place in the IIS Management console.

    Create a virtual directory called jakarta the spelling and case is significant! The path shouldreference the location of the isapi_redirect.dll file (/bin/win32/i386 by default). Check

    the Execute box.

    Fig. 18Virtual Directory Alias Fig. 19Virtual Directory Path

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    11/17

    Fig. 20Virtual Directory Access Permissions

    IIS Configuration Define Application Pool

    It is recommended that each web instance run with its own application pool. If you are configuring

    Tomcat to support an application web instance, create a separate application pool for Tomcat and

    change the web instance configuration to utilize it.

    Fig. 21New Application Pool Fig. 22Define application pool

    IIS Configuration Web Service Extension

    In the IIS Manager, right-click on the Web Service Extensions object and select New Web Service

    Extension. Enter an extension name of Tomcat, enable the checkbox Set extension status toAllowed, thenclick Add and browse to the path where the isapi_redirect.dll is located. Select the

    file and click OK. Verify that the Tomcat extension appears in the list with an Allowed status (Fig.25).

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    12/17

    Fig. 23Add a web service extension Fig. 24Specify path to isapi_redirect.dll

    Fig. 25Web Service Extensions showing Tomcat extension and Allowed status

    IIS Configuration Define the Tomcat ISAPI Filter

    The web instance needs to know that it should utilize the ISAPI redirection filter. This is done by

    registering it in the application web site properties.

    Open the properties panel of the web instance you are configuring to operate with Tomcat. Select the

    ISAPI Filters tab and click the Add button. Set the filter name to tomcat, and browse to thelocation of the isapi_redirect.dll file. Click OK. The status and priority values will not display (or

    show * Unknown * ) until the first time the redirector is loaded. The filter will not load until thefirst time it is needed.

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    13/17

    Fig. 26Add ISAPI Filter Fig. 27Web Properties dialog box

    At this point, configuration is complete. Run iisresetto reinitialize the web server environment. Any.JSP or servlets placed within the physical web structure will be intercepted by the isapi filter,

    although the uriworkermap.properties file will need to refer to the path where the .jsp or servlet fileshave been placed. This relationship will become clear when you perform the next step, which

    configures the Tomcat example files.

    IIS Configuration Tomcat Examples

    This is the part of the configuration that most often fails to function. This is likely due to not

    recognizing the relationship between the workers file, uriworkermap file, and IIS itself.

    Our example workers.properties file defines a single worker threadworker1for testing purposes.

    It defines the ajp13 protocol, binds to localhost on port 8009. These values are appropriate for

    most configurations that perform local redirection. You can define multiple worker threads tosupport multiple instances or application paths. Simply add more names to the declaration line, and

    duplicate the specification lines, editing them for each workers name.

    The example uriworkermap.properties file maps requests for specific application paths to specific

    workers. This file is configured to map the Tomcat /examples folder path to a targeted worker called

    worker1. Since we only defined one worker in the workers.properties file, the mapping file mapseverything to that worker.

    If you tried to access http://localhost/examples right now, youd experience a 404 error. This isbecause IIS is not aware of that path! Think about where the /examples path is try

    http://localhost:8080/examples. Of course, it works because the web server built into Tomcat

    (listening on port 8080) knows that the /examples URI is physically located atE:\Apps\Tomcat\webapps\examples. IIS has no knowledge of this location (yet), so it returns the 404

    error.

    Lets make IIS recognize this location by creating a virtual directory.

    Create a virtual directory called examples. The path should reference the location of the tomcat

    examples folder (\webapps\examples by default).

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    14/17

    Fig. 28Virtual Directory Alias Fig. 29Virtual Directory Path

    Fig. 30Virtual Directory Access Permissions

    Click Next to complete the installation.

    Now, when you browse to http://localhost/examples/index.html, you should see the following pagedisplay. Now that IIS can find the physical path, it can pass the request to the ISAPI filter, andTomcat can return the pages.

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    15/17

    Fig. 31- Tomcat examples page

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    16/17

    Now that the example pages are working, you might want to add some of your own .JSP code to theIIS web instance. If you create a \JTest folder in your web root and put some sample files there (I

    copied the basic-arithmetic.jsp file from the Tomcat examples to the JTest folder for my test.), the

    URI http://localhost/jtest/mytest.jsp will not work (yet). That is because .jsp is not a valid mime

    time for IIS, so IIS simply reports that it cant find (deal with) the file. Older versions of IIS wouldhave displayed the source of the file, using a default Text mime type.

    Remember the uriworkermap.properties file? It only has a reference to the /examples path

    assigned to Worker1. Add the following lines to it so references to /jtest can be assigned to a worker:

    /jtest/*=worker1/jtest/*.jsp=worker1

    Refresh your browser and you should see a different error message. This message now comes from

    Tomcat instead of IIS, proving that the redirector is now assigning the work to Worker1.

    Fig. 32Tomcat error page

    You are seeing this error for the same reason that IIS presented 404 errors for the /examples path

    earlier. You created the /jtest folder in the IIS physical paththis time Tomcat is not aware of it! We

    need to edit the server.xml file to tell Tomcat how to reference this path.

    Open server.xml, look for your definition. The Tomcat sample file will look something like

    this:

    Add this line to tell Tomcat how to map references to the /jtest path:

    Restart Tomcat and refresh your browser windowhttp://localhost/jtest/mytest.jsp should now

    properly display the page!

  • 7/31/2019 How to Install Apache Tomcat With IIS6

    17/17

    Summary

    The key to integrating IIS and Tomcat is recognizing that you actually have two web servers

    running. Requests are sent first to IIS, which must forward (redirect) them to the Tomcat web server.

    It does this by invoking the redirector, which scans the request and decides whether it shouldforward the request to Tomcat. If it does, Tomcat handles the request, otherwise, IIS handles it. The

    redirector (and Tomcat) make the decision to handle the request only if key criteria are met.

    Is it a .JSP or Servlet file? Is a worker available for the URI?

    Another important point to remember is that web servers translate the logical web paths to physicaldisk paths. If the logical path of the web server cant reach the physical path, youll get a 404 error.

    This means that if you try to access content in one web servers physical path from the other webserver, you better have some kind of configuration defined that allows that. For IIS, it means

    defining a Virtual Directory to map the web logical path to a physical folder. For Tomcat, you needto define the in server.xml to accomplish the same thing.

    Be aware that for my testing, I copied specific files basic-arithmetic.jsp to my jtest folder in IIS

    because it had no dependencies on other files. You cant do this with many of the other examplesbecause they reference external files and java beans that havent been mapped in IIS. This is

    certainly possible, but was more than I wanted to present in a basic example.