DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 14

How to Fix Apache Port Conflict

The problem was that Apache failed to start because the configured port (5003) was already in use by another process. The solution involves identifying and stopping the process using that port, and then restarting Apache.

Step 1: Analyze the Problem

The systemctl status httpd output provided key error messages:

  • Address already in use: AH00072: make_sock: could not bind to address [::]:5003: This is the most critical error. It directly states that Apache cannot start because port 5003 is already in use by another application.
  • no listening sockets available, shutting down: This is a direct consequence of the first error. Apache cannot create the necessary network socket, so it fails.
  • Failed to start The Apache HTTP Server: The final status confirming the service could not be started.

The problem is not a permissions issue, but rather a port conflict.

Step 2: Identify the Conflicting Process

You need to find which process is currently listening on port 5003. You can use the ss or netstat command for this. The sudo command is used to ensure you have the necessary privileges to see all processes.

Command:

sudo ss -tunlp | grep 5003

Expected Output:

The output will show the process that is using the port. For example:

tcp   LISTEN  0       128         *:5003      *:* users:(("other_service",pid=1234,fd=5))
Enter fullscreen mode Exit fullscreen mode

This output tells you that a service named other_service with PID 1234 is using the port.

Step 3: Stop the Conflicting Process

Once you've identified the service, you need to stop it to free up the port for Apache.

Command:

sudo systemctl stop <service_name>

Replace <service_name> with the name of the service found in the previous step (e.g., sudo systemctl stop other_service).

Step 4: Start the Apache Web Server

With port 5003 now available, you can start the Apache service.

Command:

sudo systemctl start httpd

Step 5: Verify the Solution

Finally, confirm that Apache is successfully running and is listening on port 5003.

Command:

sudo systemctl status httpd

The output should show Active: active (running).

You can also use the ss command again to confirm Apache is now using the port:

Command:

sudo ss -tunlp | grep 5003

Expected Output:

tcp   LISTEN  0       128         *:5003      *:* users:(("httpd",pid=5678,fd=4))
Enter fullscreen mode Exit fullscreen mode

This output confirms that the httpd process is successfully listening on port 5003.

Top comments (0)