Skip to content

Ubuntu Tomcat Installation

Jason A. Everling edited this page Apr 9, 2020 · 8 revisions

It is recommended to install Tomcat from source using the latest version supported by PWM.

For this example, Tomcat will be installed to /opt/tomcat

Navigate to https://tomcat.apache.org/download-90.cgi and download the latest Tomcat 9.x distribution. Unzip this file into /opt/ and rename to tomcat so that it is /opt/tomcat. This just makes it easier to update down the road without using version numbers.

Step 1: Create tomcat user

sudo useradd -c "Apache Tomcat" -r -s /usr/sbin/nologin tomcat

Step 2: Set permissions

sudo chown -R tomcat:tomcat /opt/tomcat
sudo chmod -R 0755 /opt/tomcat/bin
sudo chmod -R 0777 /opt/tomcat/logs

Step 3: Create a startup script

Use the below script to create a new file under /etc/init.d/ named 'tomcat'. Please adjust the INST_PATH variable to where you have installed Tomcat

#!/bin/bash  
#  
# Startup script for Tomcat Servlet Engine  
#  
# chkconfig: 345 86 14  
# description: Tomcat Servlet Engine  
#  
### BEGIN INIT INFO  
# Provides:          tomcat  
# Required-Start:    $remote_fs $syslog $network  
# Required-Stop:     $remote_fs $syslog $network  
# Default-Start:     3 4 5  
# Default-Stop:      0 1 6  
# Short-Description: Tomcat Servlet Engine  
# Description:       Tomcat Servlet Engine  
### END INIT INFO  
#  
  
# Directory where tomcat is installed  
INST_PATH=/opt/tomcat  
# User under which tomcat will run  
RUN_AS_USER=tomcat  
  
case "$1" in  
  start)  
        su $RUN_AS_USER -c "$INST_PATH/bin/startup.sh" -s /bin/bash  
        ;;  
  stop)   
        su $RUN_AS_USER -c "$INST_PATH/bin/shutdown.sh" -s /bin/bash  
        ;;  
  restart)  
        su $RUN_AS_USER -c "$INST_PATH/bin/shutdown.sh" -s /bin/bash  
        su $RUN_AS_USER -c "$INST_PATH/bin/startup.sh" -s /bin/bash  
        ;;  
  *)  
  echo "Usage: $0 {start|stop|restart}"  
  exit 1  
esac  
  
exit $RETVAL  

Once you have saved the file, make it set permissions and make it executable
sudo chmod +x /etc/init.d/tomcat

Now register the service using
sudo update-rc.d tomcat defaults

Now you can startup Tomcat sudo service tomcat start OR sudo /etc/init.d/tomcat start

Source installation complete!

Clone this wiki locally