Catalina localhost ERR_CONNECTION_REFUSED

apachecatalinahomebrew

I have seen a number of threads that are close but no answer quite hit the mark for my issue. I have a MacOS AMP environment for testing that was setup using homebrew and that had been working swimmingly in Catalina since about January. Then about a month ago, after a "minor" Catalina update (and resulting crash), I got ERR_CONNECTION_REFUSED when trying to access http://localhost (and 127.0.0.1 in case you are wondering about the hosts file).

At the time this happened, one thread I read suggested it could have something to do with the AV software. After I uninstalled the AV software, I was once again able to access localhost. Problem solved…or so I thought. Because after the latest Catalina update, I am once again not able to access. Thing is, I never reinstalled the AV program.

The MacOS firewall is off. Apache and PHP error logs are clear.

$ sudo apachectl configtest

Returns

Syntax OK

Any other ideas? Thanks in advance.

Best Answer

The key here is understanding the error message being generated.

  • When you see a message indicating a connection was refused (ERR_CONNECTION_REFUSED) this means that the server actively rejected the connection attempt. This is usually a firewall issue where the firewall rejects the packets.

  • When yo see a message indicating a time out (ERR_CONNECTION_TIMEOUT) this means that your client waited for a response and nothing happened. This could be due to the service not being up/running, or not installed.

  • Getting an result back from configtest only checks to see if your httpd.conf file is correctly formatted, not that it's doing what you want it to do. However, your httpd.conf file has little to do with whether your connection is refused or not other than the IP and/or port it listens on.

  • Finally, http://localhost and 127.0.0.1 (your hosts file) is a DNS related, not firewall. An error here can cause your host to be not found but not rejected.

Things to check

So, unfortunately, nothing you've looked at is related to this. What you have to look for is your firewall. First, disable your firewall and see if it's working. Next, check your httpd.conf file for the Listen directive and make sure that is set properly.

For Best Results

Unless you're hosting a website on a Mac sever (very rarely done), don't install an AMP stack on your Mac. Instead, deploy a small VM running the OS that you'll ultimately deploy to. This way, you can configure the AMP stack exactly for what you'll be using in production and macOS updates won't have any effect on your web server configuration.