How to Find Which Process Is Locking Apache Port?

When starting or restarting the Apache web server, encountering a “bind: Address already in use” error means another process has already claimed its assigned port (typically port 80 or 443). To resolve this conflict, administrators must identify the rogue process, analyze its impact, and terminate it to free up the network port. This guide covers how to use terminal utilities like netstat, ss, and lsof on Linux systems to quickly locate and stop the process locking your Apache port.

Step 1: Identify the Port Apache Uses

Before searching for the conflicting process, confirm which port Apache is trying to bind to. By default, HTTP uses port 80 and HTTPS uses port 443. You can verify your specific configuration by checking the Apache configuration files using grep.

grep -OoP '^Listen \K\d+' /etc/httpd/conf/httpd.conf /etc/apache2/ports.conf

Step 2: Locate the Conflicting Process

Once you know the port number, use one of the following command-line tools to find the Process ID (PID) responsible for the lock. You will need sudo or root privileges to see process ownership.

Option A: Using the ss Command

The ss utility is the modern, faster replacement for netstat on newer Linux distributions.

sudo ss -lptn 'sport = :80'

Option B: Using the lsof Command

The “List Open Files” command is highly effective for tracking down network sockets.

sudo lsof -i :80

This command outputs a clean table showing the command name, PID, user, and the specific protocol state.

Option C: Using the Legacy netstat Command

If you are working on an older system where ss or lsof are unavailable, netstat remains a reliable alternative.

sudo netstat -tulnp | grep :80

Step 3: Analyze and Terminate the Process

The output from the commands above will reveal a PID (for example, 1234) and a process name, such as nginx, haproxy, or a stray httpd instance.

Before killing the process, check what it is to ensure you do not terminate a critical system service:

ps -fp 1234

If the process can be safely closed, use the standard kill command. Try a graceful termination first before forcing it.

sudo kill 1234

If the process refuses to close, append the -9 flag to force-kill it:

sudo kill -9 1234

Step 4: Restart Apache

With the port cleared, you can now start or restart your Apache service without encountering the address lock error.