# Installing Tomcat 10 in cPanel -Almalinux

#### Official Documentation: <https://docs.cpanel.net/ea4/containers/easyapache-4-containers/#almalinux-and-rocky-linux> <https://docs.cpanel.net/ea4/containers/tomcat-via-containers/>

{% hint style="info" %}
The following steps require that the hosting account is already created.\
You must have SSH access enabled. It must be **Normal Shell**, the **Jailed** mode will not work.
{% endhint %}

First, you will need to log in via **SSH** using the cPanel account credentials. Do not use `su` or `sudo`.

Run this command to install **ea-tomcat** as a **container**:

`/usr/local/cpanel/scripts/ea-podman install ea-tomcat101`

This will create the application directory at:\
\
`/home/cpanelUser/ea-podman.d/container-name`\
\
E.g.: `/home/tomcattest/ea-podman.d/ea-tomcat101.tomcattest.01`\
\
Running any of the following commands will give you the container name:

`/usr/local/cpanel/scripts/ea-podman containers`\
\
`/usr/local/cpanel/scripts/ea-podman registered`

```
[tomcattest]$ /usr/local/cpanel/scripts/ea-podman containers
{
   "ea-tomcat101.tomcattest.01" : {
      "container_name" : "ea-tomcat101.tomcattest.01",
      "image" : "tomcat:10.1.24",
      "pkg" : "ea-tomcat101",
      "pkg_version" : "10.1.24-1",
      "user" : "tomcattest"
   }
}
```

Running the following command will retrieve the container name and its ports:

`/usr/local/cpanel/scripts/ea-podman running`

```
[tomcattest]$ /usr/local/cpanel/scripts/ea-podman running
{
   "ea-tomcat101.tomcattest.01" : {
      "image" : "docker.io/library/tomcat:10.1.24\n",
      "ports" : [
         "10000",
         "10001"
      ]
   }
}
```

For example, a container can be named: **ea-tomcat101.myCpanelUser.01**\
You will need to use that name to run any **Tomcat** commands for this user.

Within the directory **/home/cpanelUser/ea-podman.d/container-name**\
the most important directories are:

`/conf` Where the **server.xml** file and other configuration files are located.\
`/logs` Where the **logs** are stored.\
`/webapps/ROOT` Where the Java application files should be uploaded.\\

To verify if **Tomcat** is working, you can create an **index.jsp** file inside the directory\
\&#xNAN;**/webapps/ROOT** mentioned earlier, and add the following content:

```
<html><body>
<% out.println("Hello world! -- From JSP"); %>
</body></html>
```

Next, you should add the following code in `/conf/server.xml` in the section where it appears:

```
<Host name="localhost" appBase="webapps" unpackWARs="false" autoDeploy="false" deployOnStartup="false" deployXML="false">
```

Add:

```
<Context path="" docBase="ROOT">
         <!-- Default set of monitored resources -->
         <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
```

<figure><img src="/files/YUy2nAOW5COBMZRLumMP" alt=""><figcaption></figcaption></figure>

Next, you need to restart the **Tomcat** container:

`/usr/local/cpanel/scripts/ea-podman restart container-name`\
\
**E.g.:** `/usr/local/cpanel/scripts/ea-podman restart ea-tomcat101.tomcattest.01`

It's important to know which ports were assigned to the installed **Tomcat** container.\
You can check this by running:\
\
`/usr/local/cpanel/scripts/ea-podman running`

<div align="left"><figure><img src="/files/QggYoZJpnvU90Ibj2EUM" alt=""><figcaption></figcaption></figure></div>

{% hint style="warning" %}
The first port is the **HTTP** port and the second port is the **AJP** port.
{% endhint %}

At this point, you should be able to see the content of the **index.jsp** file we created earlier by entering this web address in the browser:\
\
`http://Server-IP:TomcatHTTP-Port/index.jsp`

E.g.: `http://69.61.102.92:10000/index.jsp`

### Steps to view Java applications from domain-based web addresses.

You need to log in to the server via **SSH**, now as **root**:

You should create these two directories, where **/user/domain** should be replaced by the cPanel user and its domain.

```
mkdir -p /etc/apache2/conf.d/userdata/std/2_4/user/domain/
```

```
mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/user/domain/
```

Then create the **custom.conf** file in the first created directory (be careful with **/user/domain**):

```
nano /etc/apache2/conf.d/userdata/std/2_4/user/domain/custom.conf
```

In this file, you should add the following **proxy** code, replacing **10001** with the second port returned by the command: `/usr/local/cpanel/scripts/ea-podman running`

```
<IfModule proxy_ajp_module>
    ProxyPassMatch "/.well-known/(.*)" "!"
    ProxyPassMatch "/(.*).jsp" "ajp://localhost:10001"
    ProxyPassMatch "/servlets/(.*)" "ajp://localhost:10001"
</IfModule>
```

<div align="left"><figure><img src="/files/w55UsVkzWFBSL4FoeCLz" alt=""><figcaption></figcaption></figure></div>

Next, create a **symlink** from this file to the second path created above.\
Remember to replace **/user/domain** with the cPanel user and its domain.

```
ln -s /etc/apache2/conf.d/userdata/std/2_4/user/domain/custom.conf /etc/apache2/conf.d/userdata/ssl/2_4/user/domain/custom.conf
```

Once done, you need to recompile the **httpd.conf** file by running this command:

```
/usr/local/cpanel/scripts/rebuildhttpdconf
```

It should not show any errors.\
If you encounter an error, it might be in the code of the **custom.conf** file we created.

Finally, restart **Apache**:

`service httpd restart`

You should now be able to view the **index.jsp** using the normal domain: **<http://domain/index.jsp>**

### Automatic redirection to **HTTPS**

First, you need to install SSL on the account using AutoSSL, as usual.

If the domain works with **<https://domain>** then you can proceed with automatic redirection.

You will need to access the **server.xml** file in the **conf** directory of **Tomcat**:

`cpanelUser/ea-podman.d/container-name/conf`

In the **server.xml** file, locate the line:

`<Connector port="8080" protocol="HTTP/1.1"`

In that line, you should add: `redirectPort="443"`

The line should look like the image below:

<figure><img src="/files/znDpkhb6CyLtYWj9ZsCR" alt=""><figcaption></figcaption></figure>

Next, add this code in the **web.xml** file of the application path at:\
`/user/ea-podman.d/container-name/webapps/ROOT/WEB-INF`

```
<security-constraint>
 <web-resource-collection>
 <web-resource-name>Entire Application</web-resource-name>
 <url-pattern>/*</url-pattern>
 </web-resource-collection>
 <user-data-constraint>
 <transport-guarantee>CONFIDENTIAL</transport-guarantee>
 </user-data-constraint>
</security-constraint>
```

Finally, restart the Tomcat container for the user:

`/usr/local/cpanel/scripts/ea-podman restart container-name`

If you test the domain or application without **https**, it should automatically redirect to the **https** version.

That's all regarding the installation of **Tomcat** itself.

### Useful Commands:

This command, executed as the cPanel user, will delete the installed Tomcat container:\
Replace **container-name** with the installed one.

`/usr/local/cpanel/scripts/ea-podman uninstall container-name --verify`

These commands will display the **Status**, **start**, **restart**, or **stop** the Tomcat container:

`/usr/local/cpanel/scripts/ea-podman status container-name`

`/usr/local/cpanel/scripts/ea-podman start container-name`

`/usr/local/cpanel/scripts/ea-podman restart container-name`

`/usr/local/cpanel/scripts/ea-podman stop container-name`

With this command, you can run certain commands as **root** quickly:

`/usr/local/cpanel/scripts/ea-podman bash container-name`

### How to modify Tomcat variables (such as memory xms/xmx)

Connect via **SSH** as the cPanel user.

Run this command to edit files as **root** temporarily:

`/usr/local/cpanel/scripts/ea-podman bash container-name`

You will need to install **vim**, **vi**, **nano**, or any file editor:

`apt update`

`apt install vim`

You should be in `/user/local/tomcat`. Go into the `bin` subdirectory\
and edit the **catalina.sh** file using **vim** or the installed editor:

<div align="left"><figure><img src="/files/4Xar1bg6FwpUb9yvbrAL" alt=""><figcaption></figcaption></figure></div>

Add the following line below the commented box:

`CATALINA_OPTS="-Xms512m -Xmx1024m"`

<div align="left"><figure><img src="/files/LMf5JJ9p4WczDAemO3HD" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
The limits in the example can be adjusted as needed.
{% endhint %}

After saving the change in the **catalina.sh** file, exit the temporary root mode with:

`exit`

Restart the container, making sure you are back in **cpanel** user mode:

`/usr/local/cpanel/scripts/ea-podman restart container-name`

Check the **Tomcat** status:

`/usr/local/cpanel/scripts/ea-podman status container-name`

Then, check that the change took effect with the command:

`ps aux |grep tomcat |grep Xmx`

<figure><img src="/files/Z8HTeJMRcFP6vBsWkkcM" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sitioshispanos.com/menu-principal/guias/cloud-hosting/administracion-con-whm/instalacion-de-tomcat-10-en-cpanel-almalinux.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
