# Installing Apache Tomcat

> Install Java and Apache Tomcat on a server you manage so you can run Java Servlets, JSP and WebSocket applications.

Source: https://helpcenter.ruachost.com/developers/web-servers/installing-apache-tomcat/

Apache Tomcat is a popular and reliable open‑source web server that specializes in running Java applications. On **ruachost.com**, you can install Tomcat to host Java Servlets, JavaServer Pages (JSP), and WebSocket applications.

## Why Use Apache Tomcat?

- Lightweight and stable Java HTTP web server.
- Supports Servlets, JSP, and WebSockets.
- Backed by a large online support community.
- Ideal for local development and production environments.

## Steps to Install Apache Tomcat

### Step 1: Install Java Development Kit (JDK)

Tomcat requires Java. Ensure the JDK is installed:

```bash
sudo apt update
sudo apt install default-jdk
```

Verify installation:

```bash
java -version
```

### Step 2: Download Apache Tomcat

1. Navigate to the Apache Tomcat official site.
2. Select the version you want to install.
3. Download the **Windows Service Installer** (for Windows) or the **tar.gz/zip** package (for Linux/macOS).

### Step 3: Install Tomcat

- ### On Windows

  1. Run the installer.
  2. Select components (Start Menu Items, Manager, Host Manager).
  3. Configure service name and shutdown port.
  4. Provide the JDK installation path.
- ### On Linux/macOS

  1. Extract the archive:

     ```bash
     tar xzvf apache-tomcat-10.x.xx.tar.gz
     ```
  2. Move it to `/opt/tomcat`:

     ```bash
     sudo mv apache-tomcat-10.x.xx /opt/tomcat
     ```

### Step 4: Configure Environment Variables

Add Tomcat environment variables to your shell profile:

```bash
export CATALINA_HOME=/opt/tomcat
```

### Step 5: Start Tomcat

- On Linux/macOS:

  ```bash
  $CATALINA_HOME/bin/startup.sh
  ```
- On Windows: Tomcat runs as a service; start it from **Services** or the **Monitor Tomcat** tool.

### Step 6: Verify Installation

Open a browser and go to:

```
http://localhost:8080/
```

You should see the Tomcat welcome page.

> **Important Notes:**
- Default port is **8080**; change it in `server.xml` if needed.
- Always stop Tomcat with `shutdown.sh` or the Windows service manager before restarting.
- Secure Tomcat by setting strong admin credentials and enabling HTTPS.
