SoFunction
Updated on 2025-03-02

apt-get install installation tomcat configuration method

useapt-getThe installed Tomcat is usually managed by the operating system's package management system, so the configuration after installation will have some characteristics that are different from manual installation. Here are the steps to configure Tomcat:

1. Install Tomcat

passapt-getInstall Tomcat (taking Tomcat 9 as an example):

sudo apt-get update
sudo apt-get install tomcat9 tomcat9-admin

2. Check the installation status

After the installation is complete, the Tomcat service will start automatically. You can check whether Tomcat is running by:

sudo systemctl status tomcat9

If Tomcat is not started, you can start it with the following command:

sudo systemctl start tomcat9

3. Tomcat configuration file location

passapt-getThe installed Tomcat configuration file is usually located in/etc/tomcat9/in the directory. The main configuration files include:

  • /etc/tomcat9/: Tomcat's core configuration file, which defines ports, connectors, etc.
  • /etc/tomcat9/: Used to configure administrative user permissions.
  • /etc/default/tomcat9: Controls the environment variables of the Tomcat process, such as JVM options and memory configuration.
  • /var/lib/tomcat9/webapps/: The default path to the web application deployed by Tomcat.

4. Configure and manage users

To use Tomcat's management interface (e.g.ManagerorHost Manager), need to beAdd user to the file:

sudo nano /etc/tomcat9/

Add the following content to the file to define a user with administrator privileges:

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

Save and exit, and restart the Tomcat service:

sudo systemctl restart tomcat9

5. Access the Tomcat Web Interface

After Tomcat is installed and started, you can access the following URL through your browser to see if Tomcat is running normally:

  • Tomcat Welcome Page:http://localhost:8080
  • Management page:http://localhost:8080/manager/html

Use yourLog in with the username and password defined in the file.

6. Modify the default port

If you need to change the default port of Tomcat (8080), you can edit itdocument:

sudo nano /etc/tomcat9/

Find the following section and modify the port number:

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

Willport="8080"Modify to the port number you want, such asport="9090". After saving and exiting, restart Tomcat:

sudo systemctl restart tomcat9

7. Configure environment variables

TomcatJAVA_HOMEEnvironment variables to find Java. You can/etc/default/tomcat9Configure JVM options and environment variables in the file:

sudo nano /etc/default/tomcat9

Modify or add the following to specify the Java runtime environment:

JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

Save and restart Tomcat to make the configuration take effect.

8. Deploy web applications

Will.warPlace files in TomcatwebappsIn the directory, Tomcat will automatically decompress and deploy the application:

sudo cp  /var/lib/tomcat9/webapps/

After the deployment is successful, the application can be passedhttp://localhost:8080/yourappaccess.

9. Log viewing

Tomcat's log files are stored in/var/log/tomcat9/in the directory. You can view the real-time logs through the following command:

sudo tail -f /var/log/tomcat9/

Summarize

useapt-getThe installed Tomcat configuration is simple because most basic configurations are automatically set. Through the above steps, you can adjust the port, user permissions, deployment application and other settings of Tomcat.

This is the end of this article about the tomcat configuration installed by apt-get install. For more related apt-get install tomcat content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!