Skip to main content

How to Install Apache Tomcat 8 On Debian

In this tutorial, we will show you how to install Apache Tomcat 8 On Debian, manually.know more with www.vcclhosting.com Blog
Environment :
  1. Debian 7
  2. JDK 1.8
  3. Apache Tomcat 8
  4. Buy Cloud KVM Server for best results and 24-7 support.
P.S Assume the JDK 1.8 is installed in /opt/jdk folder. Refer to this guide to install Oracle JDK 8 on Debian.
Note
On Debian 7, the Tomcat 8 is not included in the default apt-get repository.
Note
This guide should work in other Debian derivatives like Ubuntu or Mint.

1. Get Tomcat 8

1.1 Visit Tomcat 8 page and download the tar.gz file.
1.2 In this example, we get the version 8.0.30 via wget command.
$ cd /opt $ sudo wget http://www.eu.apache.org/dist/tomcat/tomcat-8/v8.0.30/bin/apache-tomcat-8.0.30.tar.gz 
2. Extracts to /opt/tomcat8
2.1 Extracts it to path /opt/tomcat8
$ pwd /opt $ sudo tar -xvzf apache-tomcat-8.0.30.tar.gz $ mv apache-tomcat-8.0.30 tomcat8 $ ls -lsh 4.0K drwxr-xr-x 6 root root 4.0K Dec 27 09:16 . 4.0K drwxr-xr-x 23 root root 4.0K Feb 26 2014 .. 8.8M -rw-r--r-- 1 root root 8.8M Dec 1 17:56 apache-tomcat-8.0.30.tar.gz 4.0K drwxr-xr-x 3 root root 4.0K Dec 27 09:06 jdk 4.0K drwxr-xr-x 9 root root 4.0K Dec 27 09:16 tomcat8 
3. Create a Tomcat user
3.1 Review the extracted tomcat8 folder, which is belonging to “root” user. For good practice, we should create a new user to run the Tomcat. In this example, we will create a non-login user “tomcat”, and set his home to /opt/tomcat/temp (anywhere you want).
#Usage : useradd -s  -d   $ sudo useradd -s /sbin/nologin -d /opt/tomcat/temp tomcat 
3.2 Change permissions of the /opt/tomcat8 folder, so that the new “tomcat” user can run the Tomcat.
$ sudo chown -R tomcat:tomcat /opt/tomcat8 $ pwd /opt $ls -lsh 8.8M -rw-r--r-- 1 root root 8.8M Dec 1 17:56 apache-tomcat-8.0.30.tar.gz 4.0K drwxr-xr-x 3 root root 4.0K Dec 27 09:06 jdk 4.0K drwxr-xr-x 9 tomcat tomcat 4.0K Dec 27 09:16 tomcat8 

4. /etc/init.d/tomcat8

To run Tomcat as a init service, create a custom script and put it in the /etc/init.d folder.
4.1 Create a script and save it as /etc/init.d/tomcat8
$ sudo vim /etc/init.d/tomcat8 
/etc/init.d/tomcat8
#!/bin/bash # #https://wiki.debian.org/LSBInitScripts ### BEGIN INIT INFO # Provides: tomcat8 # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Should-Start: $named # Should-Stop: $named # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start Tomcat. # Description: Start the Tomcat servlet engine. ### END INIT INFO export CATALINA_HOME=/opt/tomcat8 export JAVA_HOME=/opt/jdk/jdk1.8.0_66 export PATH=$JAVA_HOME/bin:$PATH start() { echo "Starting Tomcat 8..." /bin/su -s /bin/bash tomcat -c $CATALINA_HOME/bin/startup.sh } stop() { echo "Stopping Tomcat 8..." /bin/su -s /bin/bash tomcat -c $CATALINA_HOME/bin/shutdown.sh } case $1 in start|stop) $1;; restart) stop; start;; *) echo "Usage : $0 "; exit 1;; esac exit 0 
Note
This simple Tomcat init script is running in one of my servers, and I believe it is enough to control the Tomcat. If you are looking for more advanced features, try visiting this Tomcat init script
4.2 Assign “execute” permission.
$ sudo chmod 755 /etc/init.d/tomcat8 #Review permission $ ls -lsh /etc/init.d/tomcat8 4.0K -rwxr-xr-x 1 root root 859 Dec 27 22:07 /etc/init.d/tomcat8 
4.3 Install the script.
$ sudo update-rc.d tomcat8 defaults 
4.4 Test it
$ sudo service tomcat8 Usage : /etc/init.d/tomcat8 <start|stop|restart> #Start Tomcat... $ sudo service tomcat8 start Starting Tomcat 8... Using CATALINA_BASE: /opt/tomcat8 Using CATALINA_HOME: /opt/tomcat8 Using CATALINA_TMPDIR: /opt/tomcat8/temp Using JRE_HOME: /opt/jdk/jdk1.8.0_66 Using CLASSPATH: /opt/tomcat8/bin/bootstrap.jar:/opt/tomcat8/bin/tomcat-juli.jar Tomcat started. #Stop Tomcat... $ sudo service tomcat8 stop Stopping Tomcat 8... Using CATALINA_BASE: /opt/tomcat8 Using CATALINA_HOME: /opt/tomcat8 Using CATALINA_TMPDIR: /opt/tomcat8/temp Using JRE_HOME: /opt/jdk/jdk1.8.0_66 Using CLASSPATH: /opt/tomcat8/bin/bootstrap.jar:/opt/tomcat8/bin/tomcat-juli.jar 
Visit Tomcat default URL : http://localhost:8080
Done.

6. Extras…

6.1 To deploy a WAR file, just copy the WAR file in the /opt/tomcat8/webapps/ folder. Restart Tomcat, the war file will be extracted and deployed automatically.
  1. Example – /opt/tomcat8/webapps/lovejava.war
  2. Deployed URL – http://localhost:8080/lovejava
6.2 To change the default port (8080), just update the connector port to another port number and restart Tomcat.
/opt/tomcat8/conf/server.xml
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> 
6.3 Make the web app as the default path.
/opt/tomcat8/conf/server.xml
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- update here --> <Context path="" docBase="lovejava"> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> </Context> </Host> 
  1. Before : http://localhost:8080/lovejava
  2. After : http://localhost:8080/
  3. Contact Support for more details : support@vcclhosting.com .Create account first at www.vcclhosting.com
Now, we can access the /lovejava web app via this URL http://localhost:8080/

Comments

Popular posts from this blog

Know more about Nich Cloud ..

Overview In this article we will take a step back from my typical technical discussions and how-to guides to think about the path that lies ahead of us, in our industry. Today we have a very polarizing environment, similar in fact to the US political system.  On one side you have extremely customized on-premise environments that serve specific purpose or business niches but on the whole are hard, if not impossible to maintain and very costly. On the other side you have generic public cloud, infrastructure that always works (well almost, nothing is perfect), scales and is available at click of a button with predictable pricing structure but doesn’t fit specific purpose by default. The industry has for many years recognized these worlds were growing further apart and defined the solution as hybrid cloud management to manage them or even bridge the worlds. But gluing two polarized worlds together was only ever destined to fail. Hybrid cloud, which often drags with it the managem...

What is the Difference between Floating IP and private IP

Private IP Address A private IP address is assigned to an instance's network-interface by the DHCP server. The address is visible from within the instance by using a command like “ip a”. The address is typically part of a private network and is used for communication between instances in the same broadcast domain via virtual switch (L2 agent on each compute node). It can also be accessible from instances in other private networks via virtual router (L3 agent). Floating IP Address A floating IP address is a service provided by Neutron. It's not using any DHCP service or being set statically within the guest. As a matter of fact the guest's operating system has no idea that it was assigned a floating IP address. The delivery of packets to the interface with the assigned floating address is the responsibility of Neutron's L3 agent. Instances with an assigned floating IP address can be accessed from the public network by the floating IP. A floating IP address ...

How to calculate server requirement for your website.

Hardware requirements: Minimal hardware Verify that your hardware meets the requirements of the selected version of the system. Depending on your needs you might manage with less system resources than recommended in the table below. However, most users risk being unpleasantly surprised if they ignore these suggestions. As can be seen, it is possible to run a graphical desktop environment on older or low-end computers. In this case, we recommend installing a desktop environment that uses less resources than KDE; XFCE seems a good choice. Calculate Directory Server CPU i686 or newer (Intel Pentium Pro and higher, AMD Athlon and above) RAM 256 MB Disk Space 4 GB Swap usually not less than the RAM size Calculate Linux Desktop KDE CPU i686 or newer (Intel Pentium Pro and higher, AMD Athlon and above) RAM 512 MB Disk Space 7 GB Swap usually not less than the RAM size Calculate Linux Desktop XFCE CPU i686 or newer (Intel Pentium Pro and higher, AMD Athlon and ab...