Apache Tomcat is an open source web server and servlet container for running Java applications. It is the most popular application server used with Java web applications. There are hundreds of companies including eBay, Alibaba, and MIT that use it.
This tutorial is a step-by-step guide on how to download Tomcat 9.0.45. The code here has been tested on Debian 10. That means that if you're using a Debian-based distribution like Ubuntu or Kali Linux (or Debian itself) you can follow suit.
Requirements for Apache Tomcat 9
You must be a user with sudo Privileges. If you are not a sudo / root user, you can do the following to get this user right:
a) Create a new user
register as root and enter the following command in your terminal:
$ adduser newuser
You will be asked to enter a password. Make sure it is strong and secure. You will also be asked for additional information like your name and phone number. This is optional and trivial. You can just hit enter to skip.
b) Add the user to the sudo group
$ usermod -aG sudo newuser
You now have a sudo user named New User.
Step 1: Install OpenJDK
To install Tomcat 9, Java Standard Edition (SE) 8 or higher must be installed. To do this, install OpenJDK, an open source implementation of Java SE and Java Development Kit (JDK).
First of all, you need to update our apt package:
$ sudo apt update
$ sudo apt install default-jdk
At the time of this writing, OpenJDK14 is the latest version of OpenJDK. After the installation is complete, verify the installation by checking your Java version as follows:
$ java -version
Step 2: Create a Tomcat User
You can use Tomcat as root, but it poses a serious security threat. Therefore, you will need to create a new user to run the service with a home directory of / opt / tomcat. In this directory you install Tomcat, which was created with a shell from / bin / false so that nobody can log in.
To do this, run the following command:
$ sudo useradd -m -U -d / opt / tomcat -s / bin / false tomcat
Step 3: Install Tomcat
The official Tomcat binary distribution can be found on the Tomcat download page.
You can use the … wget Command to download the Tomcat zip file to the / tmp Directory, a temporary folder.
$ cd / tmp
$ wget https://mirror.kiu.ac.ug/apache/tomcat/tomcat-9/v9.0.45/bin/apache-tomcat-9.0.45.tar.gz
If you have problems using it wget, You can optional use the Curls Command to download Tomcat. Download first Curls::
$ sudo apt install curl
Then use Curl with the link you got from the Tomcat website:
$ curl -O https://mirror.kiu.ac.ug/apache/tomcat/tomcat-9/v9.0.45/bin/apache-tomcat-9.0.45.tar.gz
NOTE: If you used wgetThere is no need to use Curls also. Both achieve the same goal.
When the download is complete, extract the archive into the / opt / tomcat Directory:
$ sudo mkdir / opt / tomcat
$ tar -xf apache-tomcat-9.0.45.tar.gz
$ sudo mv apache-tomcat-9.0.45 / opt / tomcat /
Tomcat receives regular updates with security fixes and patches. Create a symbolic link with the name to make sure you have more control over these updates latest which points to the installation directory.
$ sudo ln -s /opt/tomcat/apache-tomcat-9.0.45 / opt / tomcat / latest
When you receive an update, all you have to do is unzip your download and point it to the symbolic link.
Next, update the permissions. The following command gives permission to the Tomcat user and the Tomcat group:
$ sudo chown -R hangover: / opt / tomcat
You need to create the shell scripts in Tomcats container Executable file directory:
$ sudo sh -c & # 39; chmod + x /opt/tomcat/latest/bin/*.sh'
Step 4: create a devices file
You need to run Tomcat as a service instead of using shell scripts. This requires a systemd device file in the / etc / systemd / system / Directory:
$ sudo nano /etc/systemd/system/tomcat.service
Now insert the following configuration.
Description = Tomcat 9.0 Servlet Container
After = network.target
Type = fork
User = hangover
Group = hangover
Environment = "JAVA_HOME = / usr / lib / jvm / default-java"
Environment = "JAVA_OPTS = -Djava.security.egd = file: /// dev / urandom"
Environment = "CATALINA_BASE = / opt / tomcat / latest"
Environment = "CATALINA_HOME = / opt / tomcat / latest"
Environment = "CATALINA_PID = / opt / tomcat / latest / temp / tomcat.pid"
Environment = "CATALINA_OPTS = -Xms512M -Xmx1024M -server -XX: + UseParallelGC"
ExecStart = / opt / tomcat / latest / bin / startup.sh
ExecStop = / opt / tomcat / latest / bin / shutdown.sh
WantedBy = multi-user.target
Save and close the file. Then reload systemctl to ensure that the new changes are confirmed by the system:
$ sudo systemctl daemon-reload
Now start the Tomcat service:
$ sudo systemctl start Tomcat
Check that the application started without errors:
$ sudo systemctl status tomcat
The above output confirms that the Tomcat server is up and running.
You can manage your Tomcat service at any time like any other systemd service:
$ sudo systemctl start Tomcat
$ sudo systemctl stop tomcat
$ sudo systemctl restart Tomcat
Step 5: Configure the firewall settings
You may need to access your server from your local network. To do this, adjust your firewall settings and open port 8080.
$ sudo ufw allow 8080 / tcp
After changing the firewall permissions, you can now access the default Tomcat page by going to Your IP address: 8080 in your web browser. At this point, don't click the link for your manager app as you will be denied access (you can configure this later).
If you want the Tomcat service to start automatically on boot, use:
$ sudo systemctl enables Tomcat
Step 6: Configure the management interface
At this point, you will not be able to access the web administration interface because you have not yet defined Tomcat users and their roles. The tomcat-users.xml is the descriptor file. Open it in your terminal like this:
$ sudo nano /opt/tomcat/latest/conf/tomcat-users.xml
When the file is opened, it displays standard text that includes comments and examples.
Add the following code at the bottom above .
The new user now has access to the web interface (manager GUI and admin GUI). Make sure to change the password to something more secure.
Step 7: test the installation
First, restart your application:
$ sudo systemctl restart Tomcat
Then enter in your browser localhost: 8080. Once you get the following page, you will know that the installation was successful.
The Tomcat Application Manager dashboard is available at http: // localhost: 8080 / manager / html. From here you can begin managing (starting, stopping, reloading, deploying, and undeploying) your applications.
The dashboard of the virtual host manager can be reached at http: // localhost: 8080 / host-manager / html. From here you can manage your Tomcat virtual hosts.
The Tomcat is ready for use
After your installation is complete, you can deploy a Java application and play around with JSPs (Java Server Pages), servlets, and more.
At this point, your Tomcat data is completely unencrypted. Your sensitive data such as passwords are sent in clear text and can be viewed by unwanted parties. To protect yourself, you can encrypt your connections with SSL.
You can also visit the official Apache Tomcat documentation to learn more about Tomcat's features. If you're struggling to get your way, you can always reach out to the vibrant developer communities like Stack Overflow online.
5 reasons why you should build your own server
Cloud computing is all the rage, but there are some practical reasons to host your own server these days.
About the author
(3 articles published)
By Jerome Davidson
Subscribe to our newsletter
Sign up for our newsletter to receive tech tips, reviews, free e-books, and exclusive offers!
One more step …!
Please confirm your email address in the email we just sent you.