How to figure which application/process is already using a port?
For example, below apache is failing to start because port 80 is already taken by some other application.
Apr 11 21:08:13 ip-172-26-0-194 systemd[1]: Starting The Apache HTTP Server...Apr 11 21:08:13 ip-172-26-0-194 apachectl[17997]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80Apr 11 21:08:13 ip-172-26-0-194 apachectl[17997]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
Here is a script which can help you find this info.
application_port_list.sh
# list out the processes using a port.# This script does not give the exact answer but potential solutions. It uses# three tools one after another.## - lsof# - netstat# - ssset -ePORT="$1"echo "Looking for application using port $PORT"if command -v lsof &> /dev/nullthen sudo lsof -i :$PORTfiif command -v netstat &> /dev/nullthen netstat -tulpn | grep ":$PORT" exit;fiif command -v ss &> /dev/nullthen sudo ss -tulp | grep ":$PORT" exit;fi