Skip to content

Tomcat server

Preparation

The first step is to copy the server to your home directory with the command:

  • Tomcat 8.5

cp -r /usr/local/apache-tomcat-8.5 ~/apache-tomcat

  • Tomcat 9.0

cp -r /usr/local/apache-tomcat-9.0 ~/apache-tomcat

  • Tomcat 10.0

cp -r /usr/local/apache-tomcat-10.0 ~/apache-tomcat

Next, you should unlock Binexec and reserve 2 TCP ports.

Configuration

In the Tomcat server configuration file /usr/home/LOGIN/apache-tomcat/conf/server.xml change the port numbers (preceded by port=: 8080 and 8005) to the previously reserved port numbers. The first two numbers must be the same.

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
<Connector executor="tomcatThreadPool"
           port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
<Server port="8005" shutdown="SHUTDOWN">

The rest of the Tomcat server configuration you need to set yourself. After changing the necessary settings, set the variable CATALINA_BASE="/usr/home/LOGIN/apache-tomcat" by adding it to the newly created setenv.sh file in /usr/home/LOGIN/apache-tomcat/bin/. LOGIN replace with the login of your hosting account. In the same file you can also insert the RAM limit for the Tomcat server using the CATALINA_OPTS variable, example:

CATALINA_OPTS='-Xms512m -Xmx1024m'

The Tomcat server is started with the following command:

~/apache-tomcat/bin/startup.sh

For the server to be available on port 80/443 you need to create a proxy domain with the destination address localhost and the same destination port as entered in Connector port.

Multiple instances

Tomcat supports serving multiple web applications on one server. To add a new one, you need to reserve an additional TCP port and add the configuration of the new page to the /usr/home/LOGIN/apache-tomcat/conf/server.xml file:

<Service name="webapp">
  <Connector port="35160" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>
  <Engine name="Catalina" defaultHost="localhost">
  <Host name="localhost"  appBase="webapp2" unpackWARs="true" autoDeploy="true">
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
          prefix="webapp2_access_log" suffix=".txt"
          pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    </Host>
  </Engine>
</Service>

Automatic start of Tomcat server

In order for Tomcat to start automatically after restarting the server, create a task in Cron. In the form in the hosting account panel, after going to Cron, select starting after reboot. When adding a task via SSH, create an entry with @reboot. Server starting command:

/bin/sh /usr/home/LOGIN/apache-tomcat/bin/startup.sh