All Products
Search
Document Center

Elastic Compute Service:Deploy a Java web environment (Tomcat)

Last Updated:May 15, 2026

Deployment options

  • Automated deployment (Terraform): Click Run Now to open Terraform Explorer and automatically create an ECS instance, a public IP address, and the required security group rules.

  • Manual deployment: Deploy Tomcat manually on an existing ECS instance by following the steps below.

Prerequisites

  1. Enable public access: A fixed public IP address or Elastic IP (EIP) is assigned to the instance.

  2. Security group rules are configured:

    • Linux: Allow inbound traffic on TCP ports 22 (Secure Shell) and 8080 (Tomcat).

    • Windows: Allow inbound traffic on TCP ports 3389 (RDP) and 8080 (Tomcat).

  3. OpenJDK is deployed on the server.

Procedure

Linux

Step 1: Download and install Tomcat

  1. Log on to an ECS instance.

    1. Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target instance.

    2. Navigate to the details page of the target instance. Click Connect and select Workbench. Follow the on-screen prompts to access the terminal.

  2. Download and extract the Tomcat installation package.

    This example uses Tomcat v9.0.91. For other versions, get the download URL from the official Tomcat website and replace it in the command.

    # Download the Tomcat installation package
    sudo wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.91/bin/apache-tomcat-9.0.91.tar.gz  --no-check-certificate 
    
    # Extract it to the /usr/local/ directory
    sudo tar -zxvf apache-tomcat-9.0.91.tar.gz -C /usr/local/
  3. Create a symbolic link.

    A symbolic link lets you upgrade Tomcat by changing only the link target, without modifying service configuration files.
    sudo ln -s /usr/local/apache-tomcat-9.0.91 /usr/local/tomcat

Step 2: Configure Tomcat as a system service

Configure Tomcat as a systemd service for automatic startup.

  1. Get the JDK path.

    sudo readlink -f $(which java)
    • JDK 8: Use the parent directory of the jre directory in the returned path.

    • JDK 11 or later: Use the returned path directly.

  2. Create the tomcat.service file.

    Replace JDK_PATH with the path obtained in the previous step.

    sudo tee /etc/systemd/system/tomcat.service > /dev/null <<'EOF'
    [Unit]
    Description=Apache Tomcat Web Application Container
    After=network.target
    
    [Service]
    Type=forking
    
    Environment="JAVA_HOME=JDK_PATH"
    Environment="CATALINA_PID=/usr/local/tomcat/temp/tomcat.pid"
    Environment="CATALINA_HOME=/usr/local/tomcat"
    Environment="CATALINA_BASE=/usr/local/tomcat"
    
    ExecStart=/usr/local/tomcat/bin/startup.sh
    ExecStop=/usr/local/tomcat/bin/shutdown.sh
    
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    EOF
  3. Start Tomcat and enable it on boot.

    # Reload the systemd configuration to apply the new service file
    sudo systemctl daemon-reload
    # Start the Tomcat service
    sudo systemctl start tomcat
    # Enable the Tomcat service to start on boot
    sudo systemctl enable tomcat

Step 3: Verify the deployment

  1. Check the service status.

    sudo systemctl status tomcat

    If the status shows active(running), Tomcat is running.

  2. Verify access.

    Open http://<ECS instance public IP address>:8080 in a browser. If the Tomcat welcome page appears, the deployment is successful.

    image

Windows

This example uses Tomcat 9.0.113 on 64-bit Windows Server 2022.

Step 1: Install and configure Tomcat

  1. Log on to an ECS instance.

    1. Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target instance.

    2. Navigate to the details page of the target instance. Click Connect and select Workbench. Set the connection method to Terminal Connection, enter your username and password, and log on to the graphical terminal.

  2. Download Tomcat 9.0.113 and extract it.

    Extract to a path without non-ASCII characters, such as C:\Java\apache-tomcat-9.0.113, to avoid path recognition issues.

    For other versions, download from the official Tomcat website.

    image

  3. Configure environment variables.

    1. Right-click This PC and select Properties > Advanced system settings > Environment Variables....

    2. In System variables, click New. Create a CATALINA_HOME variable, set its value to the Tomcat extraction path, and click OK.

      image

    3. In System variables, select Path and click Edit.

      image

    4. In the Edit environment variable window, click New, add %CATALINA_HOME%\bin, and click OK.

      image

Step 2: Install Tomcat as a Windows service and start it

Install Tomcat as a Windows service for stable background execution and automatic startup, instead of running it with startup.bat.

  1. Install the service.

    Open Command Prompt as administrator, navigate to Tomcat's bin directory, and run:

    service.bat install Tomcat9

    The message The service 'Tomcat9' has been installed. confirms success.

    Tomcat9 is a custom service name used to manage the service.
  2. Start the service and set it to automatic.

    1. Right-click Start, click Run, enter services.msc, and press Enter to open the Services Manager.

    2. Locate Apache Tomcat 9.0 Tomcat9, right-click it, select Properties, set Startup type to Automatic, and click Start.

    For garbled log characters, see Tomcat logs display garbled characters.

Step 3: Verify the deployment

Open http://<ECS_instance_public_IP_address>:8080 in a browser. If the Tomcat welcome page appears, the deployment is successful.

image

Next steps

Upload a web project

Use Workbench to upload a web application (.war file) to Tomcat's webapps directory. Tomcat automatically detects and deploys WAR files.

After deployment, access the application at http://<ECS_instance_public_IP_address>:8080/<project_name>.

Configure Tomcat

Modify the configuration file

  1. Go to the conf folder in the Tomcat installation directory and open server.xml.

  2. Modify the Tomcat configuration as needed.

    • Tomcat uses port 8080 by default. To change it, modify the port attribute value.

      Add a security group rule to allow traffic on the new port.

      image

    • Tomcat's default website root directory is webapps. To change it, modify the appBase attribute value.

      image

Set JVM memory parameters for Tomcat

Linux

  1. Create a setenv.sh file to centrally manage JVM parameters.

    Adjust heap sizes based on your instance type and application load.

    sudo tee /usr/local/tomcat/bin/setenv.sh > /dev/null <<'EOF'
    #!/bin/bash
    # Example: For an ECS instance with 2 GB of memory, allocate 512 MB
    JAVA_OPTS="-server -Xms512m -Xmx512m"
    export JAVA_OPTS
    EOF
  2. Make the file executable.

    sudo chmod +x /usr/local/tomcat/bin/setenv.sh
  3. Restart Tomcat for the changes to take effect.

Windows

  1. Go to the bin folder in the Tomcat installation directory and open catalina.bat.

  2. Add or modify the JVM parameters.

    Add or modify JAVA_OPTS near the beginning of the file (after setlocal and before call "%CATALINA_HOME%\bin\setenv.bat"). Adjust heap sizes based on your instance type and application load.

    # Example: For an ECS instance with 2 GB of memory, allocate 512 MB
    set "JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx512m"
    If JAVA_OPTS already exists, append the new parameters separated by spaces.
  3. Restart Tomcat for the changes to take effect.

Apply in production

Reduce security risks in production by completing the following steps after deployment.

  1. Delete default applications 

    Delete all default applications (docs, examples, manager, host-manager) from the webapps directory to reduce the attack surface.

    • Linux: sudo rm -rf /usr/local/tomcat/webapps/*

    • Windows: Delete all subdirectories in CATALINA_HOME\webapps using File Explorer.

  2. Configure HTTPS 

    Production environments should use HTTPS. Install an SSL certificate on a Tomcat server (Linux) and use Nginx or Server Load Balancer (SLB) as a reverse proxy for HTTPS.

FAQ

Browser times out or shows "This site can't be reached"

  • Check the security group: Verify that inbound rules allow traffic on port 8080.

  • Check the OS firewall: Ensure firewalld or Windows Defender Firewall allows traffic on port 8080.

  • Check the port listener: Confirm Tomcat is listening on port 8080.

    • Linux: ss -lntp | grep 8080

    • Windows: netstat -ano | findstr ":8080"

Tomcat fails to start

  1. Check the logs: Review catalina.out (Linux) or catalina.<date>.log (Windows) and localhost.<date>.log in the logs folder. An Address already in use error means the port is occupied. See Troubleshoot port connectivity issues on an ECS instance that can be pinged.

  2. Incorrect JDK path: Verify that the JAVA_HOME environment variable is correct.

Tomcat logs display garbled characters

This is usually caused by a mismatch between the Windows Command Prompt's default encoding (GBK) and Tomcat's log encoding (UTF-8).

  1. Open the conf folder in the Tomcat installation directory and edit logging.properties.

  2. Change all UTF-8 encoding values to GBK.

  3. Save the file and restart Tomcat. Verify that log characters display correctly.