Even though Python is the most popular programming language actually, there is still confidence in Java. So you probably needed to make applications with this veteran language. Especially in the web environment that there are so many good languages and tools, Java still resists. So, to deploy web applications made in Java is Tomcat. With the main objective that you learn how to install Apache Tomcat on Ubuntu 20.04 / Debian 10 is that this post has been written. Let us get started.
Java and its multipurpose language and that make it so good and useful to learn. Well, after coding your web application, it gets to the point where you have to deploy it. To do this, it requires a server that can interpret that Java code. Remember that we are talking about web applications. And to deploy and serve it, nothing like Apache Tomcat.
Estricatemente speaking Tomcat is not a server but transforms the caught JPS into servlets that can serve the application in question.
On the other hand, Apache Tomcat is open source and can be installed on any system running Java.
Install Apache Tomcat on Ubuntu 20.04 / Debian 10
1) Install and configure Java on Ubuntu 20.04 / Debian 10
Apache Tomcat is an application made with Java. Therefore, the first step is to install Java on Debian 10.
Open a terminal session and run the following:
:~$ sudo apt install default-jre default-jdk
Then, check the java version.
:~$ java --version openjdk 11.0.3 2019-04-16 OpenJDK Runtime Environment (build 11.0.3+7-post-Debian-5) OpenJDK 64-Bit Server VM (build 11.0.3+7-post-Debian-5, mixed mode, sharing)
As you can see, Java version 11 has been installed. It is one of the most recent and with very good support.
Now, you have to modify the
/etc/environment file and add the Java path.
:~$ sudo nano /etc/environment
And add the following:
Save the changes and close the file.
The next step is to edit the .bashrc file and add the following:
:~$ sudo nano .bashrc
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/" export PATH=$JAVA_HOME/bin:$PATH
Again, save the changes and close the file.
Next, refresh the bash.
:~$ source .bashrc
Now, type this command to test the Java path.
:~$ echo $JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64/bin/java
So, if you got the Java path from your computer, everything is correct.
2) Install Apache Tomcat on Ubunut 20.04 / Debian 10
For security reasons, it is convenient to create a new user for Tomcat. Also, add it to a group called tomcat.
:~$ sudo -i :~# groupadd tomcat :~# useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Now we can install Apache Tomcat. To do this, go to the
/opt/ folder and download with
:~# cd /opt/ :~# wget -c https://downloads.apache.org/tomcat/tomcat-9/v9.0.39/bin/apache-tomcat-9.0.39.tar.gz
--2020-10-28 19:23:24-- https://downloads.apache.org/tomcat/tomcat-9/v9.0.39/bin/apache-tomcat-9.0.39.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 22.214.171.124, 2a01:4f8:10a:201a::2
Connecting to downloads.apache.org (downloads.apache.org)|126.96.36.199|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11282879 (11M) [application/x-gzip]
Saving to: ‘apache-tomcat-9.0.39.tar.gz’
apache-tomcat-9.0.39.tar.gz 100%[=====================================================================================>] 10.76M 157KB/s in 1m 49s
2020-10-28 19:25:15 (101 KB/s) - ‘apache-tomcat-9.0.39.tar.gz’ saved [11282879/11282879]
Then, decompress it and rename the folder.
:~# tar -xzvf apache-tomcat-9.0.39.tar.gz :~# mv apache-tomcat-9.0.39 tomcat
After that, you need to change the owner of the folder and assign the required permissions so that it can run smoothly. Remember that now, we are using the root user.
:~# chown -R tomcat:tomcat /opt/tomcat/ :~# chmod +x /opt/tomcat/bin/*
Now, on the .bashrc file add the CATALINA_HOME path.
:~# nano ~/.bashrc export CATALINA_HOME=/opt/tomcat
Save the changes and close the file.
Then, refresh bash.
:~# source ~/.bashrc
After that, we can run Apache Tomcat. To do it, just type this command:
Next, open your web browser ad go
http://your-server:8080. And you will see this.
If you want to set a password to improve security of the manager web app. So, open the
:~# nano /opt/tomcat/conf/tomcat-users.xml
tomcat-user section, you have to add the username and password.
<role rolename="manager-gui"/> <user username="XXXXXX" password="XXXXXXX" roles="manager-gui,admin-gui"/>
Of course, replace the password for yours.
Then, restart Tomcat.
:~# ./shutdown.sh :~# ./startup.sh
And go to the web browser again. Next, refresh the page. And that is it.
Apache Tomcat is the best solution to deploy and serve web applications made with Java. So if you program in Java, you should learn how to manipulate Tomcat. As you have learned in this post, it is not very complex to learn how to install it in Ubuntu 20.04 / Debian 10.
Please share this post with your friends and join our Telegram channel.