Tomcat is a server for hosting java web applications, and its free and open-source.
It supports java technologies:
- java servlet
- javaserver pages (JSP)
- Java Expression Language (EL)
- Java WebSocket
Its also called a Servlet container.
It's developed by the Apache Software Foundation.
To install the Apache tomcat server, download the package from "https://tomcat.apache.org" and extract the files.
Run the below command to get the tomcat-10 package:
$ cd /opt
$ wget https://mirrors.estointernet.in/apache/tomcat/tomcat-10/v10.0.2/bin/apache-tomcat-10.0.2.zip
$ unzip apache-tomcat-10.0.2.zip
The "/opt/apache-tomcat-10.0.2" directory will be the "CATALINA_HOME" directory.
CATALINA_HOME: Represents the root of your Tomcat installation, for example
CATALINA_BASE: Represents the root of a runtime configuration of a specific Tomcat instance. If you want to have multiple Tomcat instances on one machine, use the CATALINA_BASE property
Note: Similar to maven Tomcat has a dependency with "java-OpenJDK", to install the JDK (Java Development Kit) run the below command:
$ sudo yum install java-1.8.0-openjdk-devel -y
Below are some of the key tomcat directories:
> /bin - It contains Startup, shutdown, and other scripts. The *.sh files (for Unix systems) are functional duplicates of the *.bat files (for Windows systems). Since the Win32 command-line lacks certain functionality, there are some additional files here.
> /conf - Configuration files and related DTDs. The most important file in here is server.xml. It is the main configuration file for the container.
> /logs - Log files are here by default.
> /webapps - This is where your web apps go.
To start the tomcat server run below command from $CATALINA_HOME/bin directory:
$ ./startup.sh
Tomcat runs on port 8080
To access the tomcat dashboard go to: http://localhost:8080
To install any web application all we need to do is copy the "application.war" file in the "webapps" directory and restart the tomcat server.
$ ./shutdown.sh && ./startup.sh
To access the application go to : http://localhost:8080/application
By default, the Tomcat manager is configured to be accessed from the same server where it’s installed. If you access the manager, you will get a 403 error.
For a manager to be accessible from any host/IP, you need to do the following :
1. Go to Tomcat installation and then webapps/manager/META-INF
2. Open context.xml and comment Valve section as below
<Context antiResourceLocking="false" privileged="true" >
<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
3. Save the file. Next, go to conf folder and open tomcat-users.xml to adding the following above </tomcat-users> syntax.
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
4.Save the configuration file and restart the Tomcat
Comments
Post a Comment