How to Install Latest Apache Tomcat 8.5.14 in Linux

Step 3: Changing Apache Tomcat Port

8. Do remember that 8080 is the default port tomcat usages. To change tomcat port from 8080 to any other unused port (say 137), you may do as:

First shutdown tomcat server simply by typing the below command from anywhere in the shell.

# tomcatdown

Next, open ‘/opt/tomcat/apache-tomcat-8.5.14/conf/server.xml‘ file in your favorite editor (mine is nano) to edit. Change port 8080 to 137, save and exit.

# nano /opt/tomcat/apache-tomcat-8.5.14/conf/server.xml
Sample Output
 <Connector port="137" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

After changing port to 137, restart tomcat service again and point your browser to http://127.0.0.1:137.

# tomcatup

Similarly, you can use any port of your choice. Make sure the port you are using don’t conflict with any other application/resource.

Step 4: Configuring Apache Tomcat 8

9. By default the Tomcat page is accessed by you only due its security implementation so that unauthorized users don’t have access to it.

To access admin and other sections like Server Status, Manager App and Host Manager. You need to add user accounts for admins and managers.

To add a Tomcat user edit file ‘/opt/tomcat/apache-tomcat-8.5.14/conf/tomcat-users.xml‘, in your favorite editor.

# nano /opt/tomcat/apache-tomcat-8.5.14/conf/tomcat-users.xml

10. Add the following lines just before ‘</tomcat-users>‘.

<role rolename="admin-gui"/>
<user username="admin" password="tecmint" roles="admin-gui"/>

<role rolename="manager-gui"/>
<user username="avi" password="tecmint123" roles="manager-gui"/>
Add Tomcat Users
Add Tomcat Users

Again, you need to restart Tomcat to take new changes into effect.

# tomcatdown
# tomcatup

11. After restarting Tomcat, make sure to access the admin other sections like Server Status, etc at http://127.0.0.1:137.

It you will be asked to Enter User_name and Password, you just created above, after login you will see something like the below interface.

Apache Tomcat User Login
Apache Tomcat User Login
Apache Tomcat Server Status
Apache Tomcat Server Status

Your all setting and basic configuration of Tomcat has finished now. Now we will see a simple example (beyond the scope of this article), a very basic program (JSP Program) to run in Tomcat. It would be dumb if we do not show it.

12. Create a file called tecmint.jsp under ‘/opt/tomcat/apache-tomcat-8.5.14/webapps/ROOT‘ directory.

# touch /opt/tomcat/apache-tomcat-8.5.14/webapps/ROOT/tecmint.jsp

13. Now put the below contents in the new file (tecmint.jsp), save and exit. You may edit it, if you know what you are doing.

<html>
<head>
<title>Tecmint post:TomcatServer</title>
</head>
<body>

<START OF JAVA CODES>
<%
    out.println("Hello World! I am running my first JSP Application");
    out.println("<BR>Tecmint is an Awesome online Linux Resource.");
%>
<END OF JAVA CODES>

</body>
</html>
Create JSP Program
Create JSP Program

Most of the things in the above codes are self explaining. We have put simple Java code to print two lines of output and embed it in between HTML codes, which can be accessed at http://127.0.0.1:137/tecmint.jsp.

JSP Page
JSP Page

Congratulations! You have successfully run your Tomcat Application. That’s all for now from me. We are just exploring if our readers are interested in a detailed JAVA Tutorial on Tecmint. Please let us know your valuable thoughts in the comments below. Like and share us and help us get spread.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Avishek
A Passionate GNU/Linux Enthusiast and Software Developer with over a decade in the field of Linux and Open Source technologies.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

14 Comments

Leave a Reply
  1. After installing Java and apache tomcat, i am able to start the apache service, but while i am trying to hit the apache URL i am getting 500 error, can please help.

    Reply
    • @Shanmuga,

      Are you sure your apache tomcat started up correctly? also have you opened port 8080 on firewall? If yes, do check the apache logs for any errors.

      Reply
    • @Krishna,

      The article is updated and included installation instructions for latest Apache Tomcat version..

      Reply
  2. Hi,

    Thanks for your helpful tutorials. Just wanted to ask if it is necessary to configure a java_home environment after installing the java packages. I am confused because I came across this tutorial that configured a java environment and edited the file before installing Tomcat. Why is this necessary? I’ll paste the website’s URL below. Thanks.

    Reply
  3. Nice article Avishek Kumar. I am looking forward for Java Tutorials on TecMint. I am regularly reading article on tecmint but first time I am posting comment here. Thank you for your efforts to give such nice tutorials.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.