Javascript required
Skip to content Skip to sidebar Skip to footer

How to Install Apache Tomcat in Centos 6

Apache Tomcat is a popular free and open-source web container and webserver to serve Java-based web apps or pages. Although it doesn't have all functions of the Apache HTTP server but useful for Java web developers.  It is available to install on Windows, macOS, and Linux because its requirement is the JDK platform that is easily available for almost all popular operating systems. Tomcat uses the Jasper converter to convert JSPs into servlets for execution. Well, here we are not to talk about the Apache Tomcat features instead an easy way to install and configure it on Windows 10, 8, or 7 operating systems using PowerShell or Command prompt.

Install Apache Tomcat Server on Windows 10, 8, or 7 using Chocolatey & Command prompt or Powershell.

Open Command prompt

Go to Windows 10 or 7 and search for CMD, as its icon appears, run under administrative rights. On Windows 7 you have to right-click on the result to select the Admin option.

Start command prompt admin rights windows 10

Install Chocolatey Package Manager

Now, copy the below-given block of command and past it in your Command prompt, and hit the Enter key. Give your consent for the Choco installation when the system asks for it.

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Once the installation is done, close the Command prompt and open it again with Administrator rights.

Command to install JDK on Windows 10 or 7

As we know Apache Tomcat requires Java Development Kit to run properly, so if you already have it then can skip this step otherwise use the below-given command to install OpenJDK. Here we are going to install Open source JDK's latest version.

Here we are installing OpenJDK 15

choco install ojdkbuild

In case you want to install older versions such as JDK 11

choco install ojdkbuild11

and to have OpenJDK 8

choco install ojdkbuild8

Command to install Opensource JDK Java on Windows 10

Install Apache Tomcat on Windows

Finally, run the single Choco command that will download the Apache Tomcat and configure Java Home and Cataline paths for it.

choco install tomcat

Apache Tomcat command to install on Windows 10

Start Tomcat Service on Windows in Background

Once the installation is completed, we can start the Tomcat service by command after refreshing the Environment variables. So, that the command prompt could recognize the newly added path of the Tomcat folder in the system environment.

refreshenv

Now, let's start the Tomcat Service using this command

tomcat9

Windows Defender will ask you to allow Apache Commons-Daemon Service Runner to communicate public Network. Click on Allow Access button.

Allow the access to Tomcat web interface over network

But, as you close the Command prompt, the service will automatically get stopped. Thus, if you want it to run in the background with system Windows startup, then you have set it Automatic from Service management.

  • Press Win Key + R
  • Type- services.msc
  • Search for Apache Tomcat
  • Right-click on the service
  • Select Properties
  • Set Startup type automatic and hit the Start button.
  • Press the OK button and exit the Services window.

Open Service window Set Apache Tomcat service automatic Windows

Access Tomcat Web Management interface

Now, open the browser on your Windows system and point it to localhost running on port number 8080. Example- http://localhost:8080

Web interface on localhost Tomcat

However, you won' be able to access Web Management pages such as "Server Status, Manager App, and Host-Manager". For that, we have to set the user role in the Tomcat User Config file. Follow this tutorial further.

Add User roles, username, and password:

Step 1: Open a command prompt with Admin rights and type the below command. Note– Change the Tomcat9 with the version you are using.

Notepad C:\ProgramData\Tomcat9\conf\tomcat-users.xml

Step 2: Now, copy-paste the following lines before </tomcat-users>. However, change the username and password, with the ones you want to set. Here we are using h2s and pwd.

<role rolename="admin"/>  <role rolename="admin-gui"/> <role rolename="manager"/> <role rolename="manager-gui"/> <user username="h2s" password="pwd" roles="admin,admin-gui,manager,manager-gui"/>

Set username and password tomcat

Step 3: Save the file and exit it.

Now, refresh your browser running Tomcat Tab and click on the Server Status or any other two options. It will ask you to enter your Username and password. Give the one which you have set in the file.

Apache Tomcat installation on Windows using Choco command

Access remotely

Well, you can access Apache Tomcat Server on the same Windows 10 or 7 system without any problem, however, still, remotely you cannot. Although, it is not recommended to access the management interface from a remote system, still, if you want then do the given things.

Edit Manager and Host-Manager Context XML file

1. Open Command Prompt as Admin.

2. Past the following command. Note– Replace the Tomcat9 in the below command with the version you are using.

Notepad C:\ProgramData\Tomcat9\webapps\manager\META-INF\context.xml

3. Add <!-- at the starting of the following block of text and --> at the end as showing the screenshot. After that save the file.

<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

In the same way, also edit the Host-manager file and Add <!-- at the starting of the following block of text and --> at the end.

Notepad C:\ProgramData\Tomcat9\webapps\host-manager\META-INF\context.xml

Access remotely

Now, you will be able to access your Tomcat-Server using the Ip-address of your Windows 10 or 7 computer on the remote system using the browser.

Uninstall (optional)

After some, if you don't the JDK and Tomcat on your Windows 10 or 7, then use the below command to uninstall and remove the files and service.

choco uninstall ojdkbuild

##Stop its Service first…

choco uninstall tomcat

Other Tutorials-

  • How to install Virtualbox on Windows 10 using Chocolatey
  • Steps to install Apache Server on Windows using Chocolatey
  • Install Apache web server on CentOS 7/6 with a single command

How to Install Apache Tomcat in Centos 6

Source: https://www.how2shout.com/how-to/install-apache-tomcat-on-windows-10-using-command-prompt.html