Apache Tomcat software is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket developed by the Apache Software Foundation… Although not as popular as Apache2 or Nginx HTTP servers, Tomcat is still important to some projects…
Tomcat works best when rendering web pages the include Java server page coding and Java Servlet… These languages are still required by some other protocols used by Java developers..
This brief tutorial is going to show students and new users how to instwall Tomcat on Ubuntu 16.04 / 17.10 and 18.04…
When you’re ready to install Tomcat, follow the steps below:
Step 1: Install Java JDK
Tomcat requires Java JDK to be installed in order to function… To install the original Java package, follow the guide below:
The easiest way to install Oracle Java JDK 8 on Ubuntu is via a third party PPA… To add that PPA, run the commands below
sudo add-apt-repository ppa:webupd8team/java
After running the commands above, you should see a prompt to accept the PPA key onto Ubuntu… accept and continue
Now that the PPA repository has been added to Ubuntu, run the commands below to download Oracle Java 8 installer…. the installer should install the latest Java JDK 8 on your Ubuntu machines.
sudo apt update sudo apt install oracle-java8-installer
When you run the commands above you’ll be prompted to access the license terms of the software… accept and continue..
Set Oracle JDK8 as default, to do that, install the oracle-java8-set-default package. This will automatically set the JAVA env variable.
sudo apt install oracle-java8-set-default
That should install Java JDK8 and configure it as the default…
Step 2: Download Tomcat Packages
Now that Java JDK is installed, run the commands below to donwnload Tomcat packages..
cd /tmp && wget http://mirrors.sonic.net/apache/tomcat/tomcat-9/v9.0.8/bin/apache-tomcat-9.0.8.tar.gz
Then run the commands below to extract the downloaded packages.
tar -xzf apache-tomcat-9.0.8.tar.gz
Create a directory for Tomcat files… and move the files there by running the commands below….
sudo mv apache-tomcat-9.0.8 /opt/tomcat9
Create Tomcat users by running the commands below… this users will own the Tomcat directory content..
sudo useradd -r tomcat9 --shell /bin/false
Then give the user control of the directory…
sudo chown -R tomcat9 /opt/tomcat9
Step 3: Configure Tomcat9 Service
Now that the pakcage is extracted, run the commands to open Tomcat configuration file for its default user
sudo nano /opt/tomcat9/conf/tomcat-users.xml
Then create an account with password for the user and save by copying and pasting the line below into the file.. just before the </tomcat-users>
<role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="admin" password="password_here" roles="manager-gui,admin-gui"/>
Save the file and exti..
Next, run the commands below to create a server account for Tomcat
sudo nano /etc/systemd/system/tomcat.service
then copy and paste the lines below into the file and save
[Unit] Description=Tomcat9 After=network.target [Service] Type=forking User=tomcat9 Group=tomcat9 Environment=CATALINA_PID=/opt/tomcat9/tomcat9.pid Environment=JAVA_HOME=/usr/lib/jvm/java-8-oracle/ Environment=CATALINA_HOME=/opt/tomcat9 Environment=CATALINA_BASE=/opt/tomcat9 Environment="CATALINA_OPTS=-Xms512m -Xmx512m" Environment="JAVA_OPTS=-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC" ExecStart=/opt/tomcat9/bin/startup.sh ExecStop=/opt/tomcat9/bin/shutdown.sh [Install] WantedBy=multi-user.target
Save and exit.
sudo systemctl daemon-reload sudo systemctl start tomcat.service sudo systemctl restart tomcat.service sudo systemctl enable tomcat.service
Now, open your browser and browse to the local server IP or hostname
and you should see Tomcat default page..
Click on the Manager App to logon to the backend page…
You may also like the post below: