Apache Tomcat is an open source implementation of servlet containers. The Apache Foundation is currently in charge of its development and maintenance. Install Tomcat is a must if you are a Java Developer.
At the same time, Tomcat also implements JavaServer Pages, Java Expression Language, and Java WebSocket technologies. The Java Servlet, JavaServer Pages, Java Expression Language, and Java WebSocket specifications are developed under the Java Community Process. The Apache Tomcat software is developed in an open and participatory environment and released under the Apache License version 2.
Recently was published version 9.0.12, it is a revision and maintenance version. For this reason, the most notable changes are:
- Fix multiple issues associated with using the asynchronous Servlet API in combination with HTTP/2.
- Add recursion to rewrite substitution parsing.
- Expand the information in the documentation web application regarding the use of CATALINA_HOME and CATALINA_BASE. Patch provided by Marek Czernek.
Today I will show you how to install Tomcat in Ubuntu 18.04.
1.- Install and Configure Java
In the first place, you must install Java. For this, you need a user with administrator privileges. Open a terminal and run:
:~$ sudo apt install openjdk-8-jdk
After installing it, it is necessary to configure the system to run a Java version by default.
:~$ sudo update-alternatives --config java
You should pay attention to the directory where Java is installed. In this case /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
for OpenJDK 8.
Now you must configure the Java environment. With this in mind, edit the file /etc/environment
:~$ sudo nano /etc/environment
And add the following:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"
Remember to edit correctly the location of Java, on the contrary, will not work the new configuration.
Next you have to edit the ~/.bashrc
file.
:~$ nano ~/.bashrc
At the end of the file add the following:
export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java" export PATH=$JAVA_HOME/bin:$PATH
Again, don’t forget to edit the Java location for yours.
When finished, recharge the bash.
:~$ source ~/.bashrc
Finally, it shows the JAVA_HOME directory to check that everything went well.
2. It’s time: install Tomcat
To install Tomcat in a good way, it is a good idea to do it with a separate group and user. For that reason, run as root:
:~$ sudo -i :~# groupadd tomcat :~# useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Now, download Tomcat binaries in the /opt/
directory:
:~$ cd /opt/ :~$ wget http://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.12/bin/apache-tomcat-9.0.12.tar.gz
Then decompress the file. Then rename the downloaded folder for convenience.
:~# tar -xzvf apache-tomcat-9.0.12.tar.gz :~# mv apache-tomcat-9.0.12 tomcat
Remember that you are working as a root user, for this reason, the folders will not have permissions for the rest of the users and this will cause problems. Change the owner of the folder and give it appropriate permissions to all binaries files:
:~# chown -R $tomcat:$tomcat /opt/tomcat/ :~# chmod +x /opt/tomcat/bin/*
Then you must configure the Catalina tomcat servlet container environment by editing the ~/.bashrc
file.
:~# nano ~/.bashrc
And add the following:
export CATALINA_HOME=/opt/tomcat
However, for all these changes to work, you must reload the bash:
:~# source ~/.bashrc
The moment of truth has come. Run Tomcat.
:~# /opt/tomcat/bin/startup.sh
Now you can go to your web browser and access from the server’s IP address and port 8080.
3.Set a password for the user
You already have Tomcat installed, but to access the web manager you must configure the user’s password. To do this, you must modify the file tomcat-users.xml
.
:~# nano /opt/tomcat/conf/tomcat-users.xml
And in the section tomcat-users
adds the following:
<role rolename="manager-gui"/> <user username="XXXXXX" password="XXXXXXX" roles="manager-gui,admin-gui"/>
Of course, change your username and password for yours.
Now, shutdown the server and start it again:
:~# ./shutdown.sh :~# ./startup.sh
And go to http://IP_SERVER:8080/manager/html, where you will be asked for a username and password.
And finally, you’ll access the Tomcat server management application.
As you can see, the installation is complete and you can start using the Tomcat for your needs.
The installation is really simple but you should have a little knowledge about the use of the terminal.
Tell us, what do you think about Tomcat? Have you used it?
Please share this article for your social networks.