Installing Tomcat 8 on Raspberry pi 3
In this tutorial we will be installing tomcat8 on Raspberry pi 3. I have already installed Raspbian on my pi3 which comes with java8 installed.
Check Java Version
Lets kick start our work with checking java current installed java version. You can check if java is installed by running following command.
1 |
$ java -version |
which give this kind of output :
1 2 3 4 |
pi@raspberrypi:/etc/init.d $ java -version java version "1.8.0_65" Java(TM) SE Runtime Environment (build 1.8.0_65-b17) Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode) |
Now we will create a folder in home directory, i created a folder named Tomcat. This folder will be used for installation of tomcat. Go inside that folder.
Download Tomcat 8
Next download tomcat8 using wget utility. I am installing version 8.0.41. You can install version you want
Extract the zipped tarball:
1 |
$ tar xvf apache-tomcat-8.0.41.tar.gz |
Add Tomcat user
To access tomcat manager user interface you have to configure user inside tomcat-users.xml file.
Open ~/Tomcat/apache-tomcat-8.0.41/conf/tomcat-users.xml in some text editor and add following line as child of <users> element.
1 |
<user username="admin" password="password" roles="manager-gui"/> |
This creates an admin account called “admin” who’s password is “password” and this user can access manager gui which can be used for deployment of war files.
Create Startup Script
Next we have to create a startup script using which we can start and stop tomcat. Add a startup script called tomcat to the /etc/init.d directory, with command :
1 |
$ sudo nano /etc/init.d/tomcat |
This will create file tomcat in init.d folder. Content of this file goes like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#!/bin/sh # /etc/init.d/tomcat # starts the Apache Tomcat service ### BEGIN INIT INFO # Provides: tomcat # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # X-Interactive: true # Short-Description: Start/stop tomcat application server ### END INIT INFO export CATALINA_HOME="/home/pi/Tomcat/apache-tomcat-8.0.41" case "$1" in start) if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" /bin/su pi $CATALINA_HOME/bin/startup.sh fi ;; stop) if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" /bin/su pi $CATALINA_HOME/bin/shutdown.sh fi ;; *) echo $"Usage: $0 {start|stop}" exit 1 ;; esac |
Do not forgot to change CATALINA_HOME as per your structure. Now press control + O to save file and then control + X to close editor.
1 |
$ sudo chmod 755 /etc/init.d/tomcat |
Use the update-rc.d command to add the appropriate links to the /etc/rc.d directories:
1 |
$ sudo update-rc.d tomcat defaults |
Start server
Test that the tomcat server starts:
1 |
$ sudo /etc/init.d/tomcat start |
1 | $ sudo /etc/init.d/tomcat start |
Now if everything goes without any error then you open url http://pi_ip_address:8080 then you can able to see tomcat page. Now click on manager and provide credentials and you get into Tomcat Web Application Manage page.
To stop just run
1 |
$ sudo /etc/init.d/tomcat stop |
Finally, reboot the system and the Tomcat application server should now start automatically on startup, and likewise when the system shuts down.
Please comment for more clarification.