Step-by-step guide to installing Tomcat on Linux

WBOY
Release: 2023-12-29 09:08:57
Original
1261 people have browsed it

Step-by-step guide to installing Tomcat on Linux

Tomcat Installation Guide in Linux Environment

  1. Introduction
    Apache Tomcat is an open source Java Servlet container, also known as a Web server, used for Execute Java servlets and JavaServer Pages (JSP). In a Linux environment, installing and configuring Tomcat are very common tasks. This article will provide an installation guide for Tomcat, with specific code examples.
  2. Install Java Development Kit (JDK)
    Before installing Tomcat, you need to install Java Development Kit (JDK) first. OpenJDK can be installed on Linux with the following command.
sudo apt update
sudo apt install openjdk-8-jdk
Copy after login
  1. Download and decompress Tomcat
    First, you need to download the version of Tomcat that suits you from the official Tomcat website (https://tomcat.apache.org/). After the download is complete, use the following command to decompress Tomcat to the specified directory.
tar -xvf apache-tomcat-x.x.x.tar.gz -C /opt
Copy after login

Note that you need to replace x.x.x with the specific version number and /opt with the directory where you want to install Tomcat.

  1. Configuring environment variables
    In order to facilitate the use of Tomcat commands, you need to add the Tomcat installation directory to the system environment variables. Open a terminal and use the following command to open the .bashrc file.
vi ~/.bashrc
Copy after login

Add the following lines at the end of the file, save and exit.

export CATALINA_HOME=/opt/apache-tomcat-x.x.x
export PATH=$PATH:$CATALINA_HOME/bin
Copy after login

Reload environment variables.

source ~/.bashrc
Copy after login
  1. Start and configure Tomcat
    Use the following command to start Tomcat.
startup.sh
Copy after login

Tomcat will start on the default port 8080. Visit http://localhost:8080 in the browser. If you can see the Tomcat welcome page, it means that Tomcat has been successfully installed and configured.

  1. Configure Tomcat user
    By default, Tomcat does not enable user authentication. To enhance security, user authentication can be added to Tomcat. Use the following command to open the tomcat-users.xml file.
vi $CATALINA_HOME/conf/tomcat-users.xml
Copy after login

Inside the <tomcat-users> tag, add the following code to create a new user.

<user username="admin" password="password" roles="manager-gui,admin-gui" />
Copy after login

You can modify the username, password and role according to your needs. Save and exit the file.

  1. Restart Tomcat
    Restart Tomcat to make the user configuration take effect.
shutdown.sh
startup.sh
Copy after login

Now, you can access the Tomcat management interface using the added username and password. Visit http://localhost:8080 in the browser, click the "Manager App" or "Host Manager" link, enter the user name and password, and enter the management interface.

Summary:
This article provides an installation guide for Tomcat in a Linux environment, and attaches specific code examples. By following these steps, you can easily install and configure Tomcat on your Linux system. After installing Tomcat, you can start deploying and running Java web applications.

The above is the detailed content of Step-by-step guide to installing Tomcat on Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!