To solve the problem of Tomcat port being occupied, you can: determine the occupying process (netstat or lsof); end the occupying process; change the Tomcat port (modify server.xml); disable other applications occupying the port; adjust the firewall settings (Allow inbound connections); modify the hosts file (map localhost to other IP addresses).
How to deal with the Tomcat port number being occupied
When trying to start the Tomcat server, if it cannot bind to Its default port (8080), you may receive an error that the port number is occupied. There are several ways to solve this problem:
1. Determine the process occupying the port
netstat -ano
command on Windows View the ports in use. sudo lsof -i tcp:8080
command to view the ports in use on Linux/Mac. 2. End the occupying process
kill -9 <pid>
command to end the process, where <pid>
is the process ID of the process that owns the port. 3. Change the Tomcat port
conf/server.xml
file. <Connector>
element and modify the port
attribute, for example: <Connector port="8081"
. 4. Disable other applications
5. Adjust the firewall settings
6. Modify the hosts file
C:\Windows\System32\drivers\etc\hosts
(Windows ) or /etc/hosts
(Linux/Mac), map localhost
to another IP address, such as 127.0.0.2
. The above is the detailed content of What to do if the tomcat server port number is occupied. For more information, please follow other related articles on the PHP Chinese website!