Post

How to Install Apache Tomcat on Windows



Introduction

Apache Tomcat is a popular open-source web server and servlet container that allows you to run Java applications. Installing Apache Tomcat on a Windows machine is a straightforward process. This guide will walk you through the steps to successfully install and configure Apache Tomcat on Windows.

Prerequisites

Before installing Tomcat, ensure that you have the following prerequisites:

  1. Java Development Kit (JDK)
    Apache Tomcat requires Java to run. If you don’t have the JDK installed, follow this guide.
  2. Administrative Privileges
    Ensure you have administrative rights on the Windows machine to install software and configure services.

Step 1: Download Apache Tomcat

  • Visit the Apache Tomcat Download Page.
  • Look for the Binary Distributions section and download the 32-bit/64-bit Windows Service Installer or the zip file if you prefer a manual installation.

Step 2: Install and Configure Apache Tomcat

Option 1: Using Windows Service Installer

  1. Run the Installer
    Double-click the downloaded .exe file.
  2. Follow Installation Instructions
    • Accept the license agreement.
    • Choose the installation directory (default is usually fine).
    • Enter the Tomcat Administrator and Manager passwords (for the Manager App).
    • Choose whether to run Tomcat as a service (recommended for production use).
  3. Complete the Installation
    Once finished, the installer will set up Tomcat as a Windows service.

Option 2: Manual Installation Using Zip File

  1. Extract the Zip File
    • Right-click on the downloaded .zip file and select Extract All.
    • Choose a destination folder (e.g., C:\, C:\Users\<username>).
  2. Set CATALINA_HOME Environment Variable
    • Right-click on This PC or Computer on your desktop and select Properties. If there is no shortcut on the desktop, open File Explorer, navigate to This PC in the left sidebar, right-click on it, and select Properties.
    • Click on Advanced system settings and then Environment Variables.
    • Click New under System variables and set CATALINA_HOME as the variable name.
    • Set the variable value to the path where you extracted Tomcat (e.g., C:\apache-tomcat-<version>).
    • Click OK to save.
  3. Update the PATH Variable
    • Add the bin directory of Tomcat to the Path variable (e.g., C:\apache-tomcat-<version>\bin).
  4. Configure Tomcat as a Windows Service (Optional)
    • Open Command Prompt as an administrator. Right-click on the Command Prompt icon and select Run as administrator.
    • Navigate to the Tomcat bin directory:
      1
      
      cd %CATALINA_HOME%\bin
      
    • Run the service.bat script to install Tomcat as a service:
      1
      
      service.bat install
      
  5. Configure Administration Tools (Optional)
    • Open the tomcat-users.xml file located in the conf directory:
      1
      
      C:\apache-tomcat-<version>\conf\tomcat-users.xml
      
    • Add the following configuration inside the <tomcat-users> tags:
      1
      2
      3
      4
      
      <tomcat-users>
          <role rolename="manager-gui"/>
          <user username="admin" password="admin" roles="manager-gui"/>
      </tomcat-users>
      
    • Save the changes.
    • After starting Tomcat, you will be able to access the Manager App and Host Manager by navigating to the following URLs:
      1
      2
      
      http://localhost:8080/manager
      http://localhost:8080/host-manager
      

Step 3: Start Apache Tomcat

After installing Tomcat, you have two options to start it: either run it directly as an application or as a Windows service.

Option 1: Running Tomcat Directly as an Application

If you prefer to run Tomcat as a standalone application without using Windows services, you can manually start it via the command line:

  1. Open Command Prompt as an administrator (search for cmd, right-click, and select Run as administrator).
  2. Navigate to the bin directory of your Tomcat installation:
    1
    
    cd C:\apache-tomcat-version\bin
    
  3. Start Tomcat by executing the following command:
    1
    
    catalina.bat start
    

    You can also stop it with:

    1
    
    catalina.bat stop
    

Option 2: Running Tomcat as a Windows Service

If you installed Tomcat using the Windows Service Installer, Tomcat is set up as a Windows service, which allows you to start and stop it through the system’s service manager.

  1. Press Win + R, type services.msc, and press Enter.
  2. In the Services window, scroll down to find Apache Tomcat (e.g., Tomcat10).
  3. Right-click on Apache Tomcat and select Start to launch the service.

Additionally, you can start or stop the service using the command line (run as administrator) with the following commands:

  • To start the service:
    1
    
    net start Tomcat9
    
  • To stop the service:
    1
    
    net stop Tomcat9
    

Step 4: Access Tomcat in the Browser

Once Tomcat is running, you can access the Tomcat web page in your browser at the following URL:

1
http://localhost:8080

You should see the Tomcat welcome page, which indicates that Tomcat is successfully installed and running.

If you have completed the configuration for the Manager App and Host Manager, you will also have access to the following URLs:

1
2
http://localhost:8080/manager
http://localhost:8080/host-manager

Conclusion

You have successfully installed Apache Tomcat on your Windows machine. By following these steps, you’ve set up the necessary Java environment, downloaded and configured Tomcat, and even set it up to run as a Windows service. Tomcat is now ready to host your Java web applications reliably. For advanced configurations, refer to the official Tomcat documentation.

© 2024 Java Tutorial Online. All rights reserved.