How To Run Tomcat Server At Startup On Ubuntu Server


Table of Contents

Every developer knows that for running any web applications it needs a web server. One of the most famous web servers for J2EE is Apache Tomcat. Tomcat runs applications created in JSP, JSF, Javascript, and available languages. To start the webserver you need to run a shell file called and if you need to restart your server you need to go to the folder and run the same command again. What if you could run a script for this command to start tomcat every time your system starts? In this article, we will show you how to run apache tomcat server in Ubuntu on startup, but first, let me tell you more about Tomcat.  

Apache tomcat

apache tomcat web server

According to Apache website “The Apache Tomcat® software is an open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language, and Java WebSocket technologies. The Java Servlet, JavaServer Pages, Java Expression Language, and Java WebSocket specifications are developed under the Java Community Process.”The last stable release is Tomcat 8.5.15.  

How To Install Tomcat Server?

If we were to install on Ubuntu desktop we just had to go to Tomcat download page and choose the format to download it. Since we are using the command line we have to download it using the link to the compressed file. This process was tested on from tomcat7 to tomcat9 alpha. To do it run the command below on the command line:

Step 1:

$ wget

€‹Step 2:

$ sudo mv apache-tomcat-8.5.14.tar.gz /var/opt/ 

€‹Step 2.5 (optional): €‹To avoid asking for the password change to the superuser.

$ sudo su

Step 3: €‹Extract the files.

$ tar -xvzf apache-tomcat-8.5.14.tar.gz tomcat 

Note that if you didn’t use step 2.5 you will have to use the above command with sudo.

Step 4:

Create the init script in /etc/init.d/tomcat8 and include  the information below - #!/bin/bash### BEGIN INIT INFO
# Provides: tomcat7
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop Tomcat server
start() {
sh /var/opt/tomcat8/bin/
stop() {
sh /var/opt/tomcat8/bin/
case $1 in
start|stop) $1;;
restart) stop; start;;
*) echo "Run as $0 "; exit 1;;
Esac Step 5:Change its permissions and add the correct symlinks automatically: $ chmod 755 /etc/init.d/tomcat7
$ update-rc.d tomcat7 defaults 

Now your tomcat will start when your system starts and you can control it with service tomcat7 <stop|start|restart>Note for starting Tomcat you must have OpenJDK or JDK installed.  


‹There are many solutions for running web server applications and this is only one of them. If you are a web developer or server admin, this script could help you keep your server always up, without needing to get worried if you forgot to run in on your system start. Leave your thoughts in the comment section below.

Linux TutorialsUncategorized