11

I have my Mac's local apache server running and when I visit localhost I get the standard "It Works" page. The "It works" page was cached - it is in fact broken the same as 127.0.0.1. When I visit 127.0.0.1 however chrome gives me Error code: ERR_CONNECTION_REFUSED. So I ran a telnet. Result:

harryg$ telnet localhost 80
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
telnet: Unable to connect to remote host

But scutil gives this:

harryg$ scutil -r localhost
Reachable,Local Address,Directly Reachable Address

Any idea why it isn't working? Is apache listening on some different port? If so how do I check? I have some local vhosts which should be accessible by some local .dev virtual hosts that I've added to my hosts file. E.g. 127.0.0.1 home.dev but they too give the error above.

Edit

It seems nothing is listening on port 80. When I run sudo lsof -iTCP:80 -sTCP:LISTEN I get no output. Apache seems to be running though - I have run apachectl restart` many times.

4
  • could you check is your webshare is working with this tool; clickontyler.com/web-sharing
    – siniradam
    Oct 17, 2014 at 13:31
  • Your localhost is working perfectly fine. Apache isn’t. Update your question to represent this fact and don’t forget to include the relevant bits of your Apache config and its log files.
    – Daniel B
    Oct 18, 2014 at 20:42
  • I had a similar problem and was able to solve it: stackoverflow.com/questions/26454160/…
    – Xaver
    Oct 20, 2014 at 18:46
  • The normal way to do this on Mavericks/Yosemite is to port forward from port 80 to port 8080. See gist.github.com/mindw0rk/dcc6c02a92b49bde0f13 for an example of how to set this up using pfctl, then change your apache config to use Listen 8080. You'll be able to connect to port 80 & traffic will be forwarded to apache. (in our dev shop everyone uses this setup, except with nginx)
    – bazzargh
    Oct 23, 2014 at 12:38

3 Answers 3

11

Check your Apache config with this command:

sudo apachectl -t

This tests the config files and tells you if there's an error. Running sudo apachectl start does not output config file syntax errors to the logs for some reason.

1
  • Exact same problem here. sudo apachectl -t returns Syntax OK. What then? Mar 10, 2017 at 20:41
2

This command should tell you what on which port and which IPv(4/6) address your Apache is listening :

sudo lsof -P -n -iTCP -sTCP:LISTEN | grep httpd

If there is nothing listening, what do you get from this ?

sudo serveradmin status web
sudo serveradmin settings web
ps -acx | grep http

.

At last resort :

sudo serveradmin stop web

Open Console.app and place a bookmark

sudo serveradmin start web

Check the logs

7
  • There was a configuration file issue that prevented Apache from starting at all! Cached pages led me to believe it was running for localhost but not for my local IP.
    – harryg
    Aug 7, 2014 at 9:38
  • Ok cool, serveradmin trigger httpd, and generally generates startup logs, have you been able to resolve the issue ? what is the error message plz (for other members)? Aug 8, 2014 at 0:14
  • Yeah it's solved. I had forgotten to uncomment an apache vhosts module so Apache hit an error when it saw VirtualDocumentRoute in my vhosts config file.
    – harryg
    Aug 8, 2014 at 9:29
  • 2
    hey harryg, if you get the chance update the status to resolved. Aug 19, 2014 at 4:29
  • I had this issue and silent failure when starting apache. Nothing in logs, due to a syntax error in the config. This command surfaced it: sudo apachectl -t Oct 23, 2014 at 12:11
0

I believe the default port is 8080, but you can check the httpd.conf file for the ports that Apache is listening on.

3
  • 8080 doesn't work, and my config file has Listen 80 in it.
    – harryg
    Aug 4, 2014 at 21:36
  • Can you see Apache running, perhaps with a "ps aux"? Also, does the error log show anything? Default location should be /var/log/apache2/error_log
    – John Townsend
    Aug 4, 2014 at 21:45
  • what is the output of netstat -tulpn | grep :80?
    – sardean
    Aug 5, 2014 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.