On this page

macOS, Apache and ERR_CONNECTION_REFUSED fix

Fix ERR_CONNECTION_REFUSED on macOS: Learn how to delete the Apache PID file to resolve server startup issues.

The ERR_CONNECTION_REFUSED error is a common issue that can occur when trying to access a website or a local server. It indicates that the Apache server has refused the connection attempt, which can be due to various reasons.

This usually appears like This site can’t be reached and looks like on the following screenshot:

The content of the image is a screenshot showing an error message stating "This site can't be reached" with details about the connection refusal and suggestions to check the connection, proxy, and firewall settings.

Fixing Apache ERR_CONNECTION_REFUSED error on macOS

If the Apache server is not starting up properly, one potential solution is to delete the Apache PID file. This can help resolve issues where the server is unable to start because the PID file is corrupted or points to a non-existent process.

After deleting the PID file, you can then try to restart the Apache server.

Removing the Apache HTTP server’s PID file on macOS
sudo rm /usr/local/var/run/httpd/httpd.pid

Understanding the terminal command

The terminal command sudo rm /usr/local/var/run/httpd/httpd.pid performs several actions:

  1. sudo: this prefix stands for superuser do. It allows you to run commands with administrative privileges. This is necessary because removing files from certain directories typically requires higher permissions than those granted to regular users.
  2. rm: this is the remove command in Unix-like operating systems (macOS). It is used to delete files and directories.
  3. /usr/local/var/run/httpd/httpd.pid: this specifies the path to the file that will be deleted. The path breaks down as follows:
    • /usr/local: A standard directory where locally installed software and data reside.
    • /var/run: A temporary filesystem (tmpfs) that holds runtime data. Files in this directory are cleared on reboot.
    • httpd: refers to the Apache HTTP Server.
    • httpd.pid: this is the process ID file for the Apache HTTP Server. When Apache starts, it creates this file to store its process ID (PID). This file is used by system administrators to stop the server gracefully by sending a signal to the PID stored in this file.

Summary

In summary, the command sudo rm /usr/local/var/run/httpd/httpd.pid uses superuser privileges to delete the Apache HTTP server’s PID file located in the /usr/local/var/run/httpd/ directory. This action can be taken to restart the Apache service by deleting the PID file, forcing the server to start anew upon the next request, or simply to clear out old PID files if they are no longer needed.

Related posts

Comments

Leave a Reply

Real-user monitoring for Accessibility, Performance, Security, SEO & Errors (SiteLint)