localhost is always responding with "Connection refused: localhost:80" I've been working with the integrated webserver of OS X El Capitan for a while now.
I am developing a website project and thus, this was the perfect solution for me.
I was starting the local server using php -S localhost:8088 -t . in the specific directory containing the website data (index.php etc.).
Everything was working fine until I refreshed the page one day and it suddenly printed: Connection refused: localhost:8088. There were no changes made to any config files or anything else.
It doesn't matter which port I am using, it always refuses the connection. Sending a request to 127.0.0.1 in my browser tells me It works!. But, once I am starting the server and calling 127.0.0.1:8088, my browser responds with its default page displaying that the connection has been refused, as if I did not start/run the server.

The first thing I did was checking whether the Apache config is broken.
But, apachectl configtest printed Syntax OK.

When I tried to ping localhost, I encountered a 100% package loss, so at first I thought that the bug may be located inside the hosts file.
cat /etc/hosts/ printed out the following:

##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost


Looks appropriate, doesn't it?
So, I checked my firewall options and discovered that I had "Stealth mode" activated. Unchecking it resulted in having the ICMP-packages finding their way correctly and there was no package loss any longer.

The thing is that I don't know why this problem suddenly occured and how I am able to fix it. I already restored all Apache config files to the originals, but that didn't solve it neither.
It seems to be listening on that port, but I can't access the server as it always refuses the connection.
Even if the server is not started, accessing localhost prints Connection refused: localhost:80. I don't know where the error could be located.
Apache's error log didn't show anything conspicious neither.

sudo lsof -i -n -P | grep TCP | grep LISTEN showed that httpd is using IPv6 only, so that should work.

If you need any more (config) files, just request them.
Thanks!
It turned out that the problem occured only in Opera, not Safari or any other browser. I found out that I had Opera Turbo enabled which would of course let me access my own localhost correctly.