How to Install Latest Apache Tomcat 8.5.14 in Linux - Part 2

Channel: Tomcat Linux
Abstract: save and exit. # nano /opt/tomcat/apache-tomcat-8.5.14/conf/server.xmla very basic program (JSP Program) to run in Tomcat. It would be dumb if we do n
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

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 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

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

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.

Pages: 1 2

Ref From: tecmint
Channels: apache tomcat

Related articles