I have downloaded and installed apache, php, phpmyadmin, mysql via macports. Everything was working fine before upgrading to macOS Sierra.

After the upgrade whenever I try to access localhost I get the following error message: "This site can't be reached, localhost refused to connect."

This is happening although my settings in the apache http.conf file remain the same.

I am also providing the content of the hosts file       localhost broadcasthost
::1             localhost

Any advice?

  • Have you verified that all of those services are indeed running? – samh Oct 2 '16 at 11:44
  • if i run the "sudo port load apache2" command i get the following respond from the terminal "/opt/local/etc/LaunchDaemons/org.macports.apache2/org.macports.apache2.plist: service already loaded", so i am pretty sure that apache is running. – vasilisdmr Oct 2 '16 at 11:50
  • Please add the content of your /etc/hosts file. Does work? Maybe related: apple.stackexchange.com/questions/252466/… – klanomath Oct 2 '16 at 12:21
  • Did you run a configtest to be sure everything is OK? I had a similar issue with the stock install of Apache, something in the update broke one of the dependent packages. – dr.nixon Oct 2 '16 at 14:44
  • Just did the config test and the results were the following: "httpd: apr_sockaddr_info_get() failed for username-MacBook-Pro.local" "httpd: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message". So i followed this tutorial and "mdshaonimran.wordpress.com/2011/10/17/…" and the error went away, but i still get the refuse message when trying to visit localhost. – vasilisdmr Oct 2 '16 at 15:01

I solved this by commenting out this line from my httpd.conf:

LoadModule unique_id_module modules/mod_unique_id.so

I'm not very familiar with mod_unique_id, but it doesn't seem critical to have on my local development server (your situation might be different).


This module provides a magic token for each request which is guaranteed to be unique across "all" requests under very specific conditions. The unique identifier is even unique across multiple machines in a properly configured cluster of machines. The environment variable UNIQUE_ID is set to the identifier for each request. Unique identifiers are useful for various reasons which are beyond the scope of this document.


After updating to macOS Sierra, Apache httpd moves the old httpd.conf to httpd.conf.pre-update and place the new one. In order to work the localhost work please try the below procedure:

cd /etc/apache2/  
sudo mv httpd.conf httpd.conf-afterupdate  
sudo mv httpd.conf.pre-update httpd.conf  
sudo apachectl configtest  
sudo apachectl restart  

Then test:

curl -I -L localhost
  • 3
    sudo apachectl configtest gave me all the errors! Life saver, thank you. – Joshua Kissoon Oct 29 '17 at 23:44
  • 2
    Thanks so much for the answer! By the way, how did you figure out this solution? I didn't get any errors with configtest (was I supposed to get oone?) and honestly, I wouldn't know where to start looking for an answer myself. – Rahul Govind Mar 31 '18 at 16:59
  • You save my huge time, Thanks a lot. – Sila Khatun Apr 19 '20 at 18:17

I had the same problem. I ran sudo apachectl configtest and got the message:

AH00526: Syntax error on line 6 of /private/etc/apache2/other/default-ssl.conf:

Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration

I just renamed the default ssl config file so it's not to be loaded anymore. A apache restart later, everything came back.


I had same issue and i solved commenting mod_proxy_hckeck in httpd.conf

LoadModule proxy_hcheck_module libexec/apache2/mod_proxy_hcheck.so

EDITED: I found in apache.org that this module requires mod_watchdog, but this module is commented, so just comment mod_proxy_hcheck or uncomment mod_watchdog LoadModule watchdog_module libexec/apache2/mod_watchdog.so

hope it works!

  • Commenting out mod_proxy_hcheck solved it for me, too. Before that, Apache would silently fail to bind to its port. – Otto G Nov 16 '16 at 14:38

I was having the same issue. Luckily I was able to solve the problem by accident. After a Suitcase Fusion load error, I realized the problem is not being caused through apache. The problem is main /etc/ file.

Replace The Hosts File

You can download a default Mac OS hosts file from http://cs.us.extensis.com/HostsFile/hosts.zip.

Unzip the hosts file; it should have no file extension In the Finder, go to Go > Go to Folder For “Go the the folder” enter “/etc” and press Enter Drag the hosts file into the etc folder; enter a Mac OS administrator username and password when asked Once you have placed the hosts file in the etc folder:

Open the Terminal application Enter the following command and press Enter: sudo chmod 644 /etc/hosts Enter your Mac OS password and press Enter You may see bullets, key icons, or nothing as you type your Mac OS password into the Terminal window, depending on the version of Mac OS you are using. This is normal.

Clear Your Mac OS DNS Cache

In the Terminal window, enter the following command and press Enter: sudo killall -HUP mDNSResponder Restart your Mac Cause

Suitcase Fusion uses the hosts file to find and connect to the type core using the loopback address ( or localhost). If the hosts file is not present, or the entry for points to a name other than localhost, you will see one of the error messages displayed above.

If Suitcase Fusion cannot resolve localhost to, you will get the first error message; if the type core cannot resolve localhost to, you will get the second error message.

If the hosts file has been modified, it may be removed when upgrading to a new version of Mac OS. Third-party applications or network utilities may incorrectly change the localhost entry as well. For more information, see How to Edit the Hosts File in Mac OS X with Terminal.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .