Although not as popular as Apache2 or Nginx HTTP servers, Tomcat is still important to some projects. Tomcat works best when rendering web pages that include Java server page coding and Java Servlet. These languages are still required by some other protocols used by Java developers. Tomcat requires Java SE 8 or later to be installed on the system. We showed you how to install OpenJDK on Ubuntu which will be needed to run Tomcat. Also, for students and new users learning Linux, the easiest place to start learning is Ubuntu Linux. Ubuntu is the modern, open-source Linux operating system for desktops, servers, and other devices. To get started with installing and configuring Tomcat on Ubuntu, follow the steps below.
How to install OpenJDK on Ubuntu Linux
Tomcat requires Java JDK to be installed to function. You can either install Oracle Java JDK or its open-source alternative called OpenJDK. For a more detailed installation of Java, read our post here. You can also run the commands below to install the default OpenJDK on Ubuntu. Once the OpenJDK is installed, verify it by checking the Java version: The command should output something similar to the lines below: Java should be installed and ready to use
How to create a Tomcat user and group
To properly run Tomcat, you’ll want to run Tomcat as its user without root privileges. To do that, create a new user and group that will run the Tomcat service. First, create a new tomcat group called tomcat. Linux systems usually create groups based on the account name. Next, create a new tomcat user called tomcat and make the user a member of the tomcat group above. Well also want to make /opt/tomcat the home folder for the tomcat user. To do that, run the commands below We’re ready to download the Tomcat package.
How to download the Tomcat file
At this stage, we’ve to install OpenJDK, created a Tomcat account and we’re ready to download and configure Tomcat. At the time of this writing, the latest version of the 10 series was 10.0.12. You can get the latest from the link below. If you find a newer release at the link below, then download it instead. Download Tomcat package After downloading, create a Tomcat home folder at /opt/tomcat. Then extract the downloaded folder into /opt/tomcat. To do that, run the commands below: Next, give the tomcat user control of the entire directory and make all the scripts in the bin location executable.
How to configure the Tomcat service
Now that the package is extracted, run the commands to open the Tomcat configuration file for its default user Then create an account with a password for the user and save by copying and pasting the lines below into the file, just before the Save the file and exit. Next, run the commands below to create a server account for Tomcat then copy and paste the lines below into the file and save Save and exit. After that, run the commands below to reload the systemd profiles and enable the tomcat service. To check if Tomcat is running or not, run the commands below: You should get a similar screen as below; You should see the Tomcat service running. Now, open your browser and browse to the local server IP or hostname and you should see the Tomcat default page. Click on the Manager App to log on to the backend page. By default, Tomcat restricts access to the Manager and Host Manager apps to connections coming from the local server only. If you want to access the Tomcat server remotely, you’ll want to whitelist the remote IP address to be allowed. To change the IP address restrictions on these, open the appropriate context.xml files. For the Manager app, type: For the Host Manager app, type: Inside, comment out the IP address restriction to allow connections from anywhere. Alternatively, if you would like to allow access only to connections coming from your IP address, you can add your public IP address to the list: context.xml files for Tomcat webapps should look similar to the one below: Save and close the files and you’re done! Restart the Tomcat service by running the commands below. That should do it. Conclusion: This post showed you how to install Tomcat on Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.