Installing TOMCAT

Apache Tomcat Web Server

How to Install and Configure?

I had to use Java Spring framework for one of my projects and I needed to install Apache Tomcat Server to run the code I write. I've followed many tutorials but they were all stuck in the middle. Then I thought of writing a tutorial here to help installing it to anyone who needs the great Apache!

Installing JAVA

For anything I do, I need JAVA. I'll update the apt in my system first
sudo apt-get update
Now I can actually install JAVA!
sudo apt-get install oracle-java8-installer

Once the installation is complete, I'm going to check whether it is installed correctly. I simply type java -version and see the JAVA version installed in my system!

Setting up JAVA Environment

To use JAVA, I need to setup it's JAVA_HOME system variable. Just like we setup JAVA path in Windows. I will check the JAVA installation directory first. sudo update-alternatives --config java will list me out current JAVA directories and their details. I'm using vim editor to edit the file containing system variables. To install vim, simply call;

sudo apt-get install vim

Once vim is there, type vi ~/.bashrc which will bring me with the bashrc file in vim editor. Press Shift + g and go to the bottom of the screen and press o. Now I can insert JAVA_HOME variable. To do this, either copy and paste or type the following;
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre
export PATH=$JAVA_HOME/bin:$PATH
Now press Esc and type :wq to save and exit the screen.

Installing Tomcat

Now comes the real business. To install and use Tomcat, first download the latest tomcat release from the official site. Once it is downloaded, extract the files to a relevant folder. (I'm using /opt/ folder as the root for tomcat directory).

sudo tar xvf apache-tomcat-8.5.9.tar.gz -C /opt/

Now try to set CATALINA_HOME system variable with the path to tomcat root directory. In my case it is;
export CATALINA_HOME=/opt/apache-tomcat-8.5.9

Now that everything is set, I'm going to create some executables to help me running the tomcat server. I will simply make all the shell files inside the /bin/ folder executables. Go to the root folder using cd /opt/apache-tomcat-8.5.9/ command in console and type;

chmod +x bin/*.sh

Now I can start our server by simply commanding;

bin/ run

If everything is running as they should be, I'm going to have a long log print and at the end, Server startup in 559 ms. If this doesn't come and I end up with some Bind exception or a socket already exists error, try to stop the server and run again using the stop command bin/ stop and bin/ run. In case of a socket already exists error, I can simply change the default socket which is 8080 to a different number like 8008 ... in the /conf/server.xml file using vim or gedit.

Sometimes there can be an error in the CATALINA_HOME saying Cannot find /opt/bin/ Try unset CATALINA_HOME which will unset the path I've set. If the server has started with the successful message, let's try opening the tomcat homepage which looks like this


Popular posts from this blog

Python Laboratory Excersices


Find Maximum Number in a Nested List Recursively