How to Install Apache Tomcat Server on Ubuntu 20.04. Apache Tomcat is a free and open source application used to run Java based applications on the web. It is developed by the Apache Foundation and maintained by an open community of developers. It allows developers to write dynamic web content based on Java. Tomcat allows the webserver to handle Java-based dynamic web content. Tomcat also supports other Java server technologies such as JavaServer Pages (JSP), Java Expression Language, and Java WebSocket.
Tomcat is very popular and boasts a market share of over 60%. Apache Tomcat is the best solution for you if you are looking to host applications that process thousands of requests.
In this post, we will show you how to install Apache Tomcat with Nginx as a reverse proxy on Ubuntu 20.04.
Tomcat is a Java based application. So the default Java Development Kit (JDK) package must be installed on your server. If not installed, you can install it using the following command:
apt-get install default-jdk -y
Once the Java is installed, verify the Java version using the following command:
java --version
You should see the Java version in the following output:
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
Our next step of the guide how to Install Apache Tomcat Server on Ubuntu 20.04 we will need to Install Tomcat. At the time of writing this tutorial, Tomcat 10 is the latest version available on the internet. You can download it directly from the Tomcat download page or use the following command to download it on the terminal:
Instead of starting and stopping the Apache Tomcat service manually. It is a good idea to create a systemd service file to manage the Apache Tomcat service.
For security reasons, it is recommended to create an admin user and password to access the Tomcat application. You can create it by editing tomcat-users.xml file.
nano /opt/tomcat/conf/tomcat-users.xml
Add the following line before the </tomcat-users> tag:
Note: Replace the username and password value with your preferred value.
Save and close the file when you are done.
Enable Tomcat Remote Access
By default, the Tomcat manager app and the host-manager app can be accessed only from the localhost. If you want to enable remote access for both applications then you will need to edit the context.xml file for both applications
To enable remote access for the Tomcat manager application, edit the context.xml file as shown below:
Configure Nginx as a Reverse Proxy for Apache Tomcat
It is recommended to install and configure the Nginx as a reverse proxy to redirect all the traffics coming on port 80 to Apache Tomcat Server on port 8080.
To do so, install the Nginx server package using the command below:
apt-get install nginx -y
Once the Nginx is installed, create an Nginx virtual host configuration file for Tomcat.
nano /etc/nginx/conf.d/tomcat.conf
Add the following configuration to redirect all traffic coming on domain tomcat.yourdomain.com on port 80 to the Apache Tomcat server running on the local host on port 8080.
Save and close the file when you are finished. Then, run the following command to verify the Nginx for any syntax error.
nginx -t
You should see the following output.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Finally, restart the Nginx service to apply the configuration changes.
systemctl restart nginx
You can also verify the status of the Nginx service using the command below:
systemctl status nginx
You should see the following output:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-12-02 08:50:17 UTC; 4s ago
Docs: man:nginx(8)
Process: 5088 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 5104 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 5105 (nginx)
Tasks: 2 (limit: 2353)
Memory: 2.7M
CGroup: /system.slice/nginx.service
├─5105 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─5106 nginx: worker process
Dec 02 08:50:17 server systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 02 08:50:17 server systemd[1]: Started A high performance web server and a reverse proxy server.
In the next section of this guide of how to Install Apache Tomcat Server on Ubuntu 20.04 we will open your favorite web browser and access the Tomcat web interface using the URL http://tomcat.yourdomain.com. You should see the Tomcat web UI on the following screen:
Click on the Manager App to access the Tomcat Manager application, you will be asked to provide a Tomcat admin username and password:
Provide your Tomcat admin username, password and click on the Sign In button. You should see the Tomcat Manager application dashboard.
If you want to access the Host Manager application, click on the Host Manager. You should see the following screen:
How to Install Apache Tomcat Server on Ubuntu 20.04 Conclusion
In this post, you learned how to install Apache Tomcat with Nginx as a reverse proxy on Ubuntu 20.04 server. You can now start creating your Java application and host it using Tomcat.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
51vote
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.