1

When I try to access locahost:8080, I get

The localhost page isn’t working

localhost didn’t send any data.
ERR_EMPTY_RESPONSE

but if I try:

127.0.0.1:8080, I get the response I'm looking for

I believe this has something to do with the httpd (apache) that I just updated with homebrew httpd24(httpd.2.4)?

I followed the instructions for updating from this site: https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions

klanomath
  • 167
  • 1
  • 1
  • 5
pixel 67
  • 113
  • 1
  • 6
  • 1
    does "ping localhost" resolve to 127.0.0.1 ? You can check /etc/hosts as well. – Meiko Watu Dec 10 '16 at 17:33
  • Yes, ping localhost resolves to 127.0.0.1 127.0.0.1 localhost 255.255.255.255 broadcasthost – pixel 67 Dec 10 '16 at 17:44
  • Did you have old config files which define a virtual host? Or is there anything in the apache log files? Do you see anything happening when you tail all log files and try to access localhost? "tail -f /usr/local/var/log/apache2/*" – Meiko Watu Dec 10 '16 at 17:44
  • I'm not sure, not really knowledgeable about the server configs, just fiddle until I get things working Here is a link the result when I run the tail call: [gist file](https://gist.github.com/anthonybrown/a94bd707164934807d0ca547da8afa24) – pixel 67 Dec 10 '16 at 17:48
  • It looks like there is still another process running which uses the ports. So I guess you would need to shut it down first – Meiko Watu Dec 10 '16 at 17:50
  • I did a ps aux | grep localhost:8080
        → ps aux | grep localhost:8080 
        tony             66074   0.0  0.0  2444056    700 s003  U+   12:52PM      0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude        -dir=.git --exclude-dir=.hg --exclude-dir=.svn localhost:8080
    
    – pixel 67 Dec 10 '16 at 17:53
  • Look for the process with: "ps -aef | grep httpd | grep -v grep". Since the process of apache is called httpd and not localhost – Meiko Watu Dec 10 '16 at 17:54
  • You can kill the runnig apache with the following command: ps -aef | grep " httpd " | grep -v grep |kill $(awk '{print $2}') – Meiko Watu Dec 10 '16 at 17:55
  • [This](https://gist.github.com/anthonybrown/6edb0a65411c77d253876b8e51598a59) is the link to the output Sorry for the formatting, so I should just run `kill` on all httpd process? – pixel 67 Dec 10 '16 at 17:56
  • Yeah, since there is another apache process running, you cannot start your updated version. You need to stop or if that doesn't work kill them, before you can start your new server with apachectl start – Meiko Watu Dec 10 '16 at 17:58
  • Ok, that makes sense. I'll try. Thanks for the help, I appreciate it! – pixel 67 Dec 10 '16 at 17:58
  • No worries, the command: * ps -aef | grep " httpd " | grep -v grep |kill $(awk '{print $2}') * Should work and do the job for you. After that you can start the new apache with * sudo apachectl -k restart * – Meiko Watu Dec 10 '16 at 18:00
  • seems to be taking a long time to run that command, nothing happening yet – pixel 67 Dec 10 '16 at 18:01
  • I have most of Apache and PHP stuff installed with `homebrew` if that helps at all? – pixel 67 Dec 10 '16 at 18:02
  • If it's taking a long time, then it most probably tries to restart every killed apache process. Can you just try to shut it down with: * sudo apachectl stop * and check for running processes afterwards ? – Meiko Watu Dec 10 '16 at 18:04
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/49897/discussion-between-pixel-67-and-meiko-watu). – pixel 67 Dec 10 '16 at 18:05
  • `httpd (pid 39269?) not running1 – pixel 67 Dec 10 '16 at 18:05
  • If it's OS X's built-in apache running, you can deactivate it with `sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist`. If that says "Could not find specified service", it's not activated so you need to look elsewhere for the source of the problem. – Gordon Davisson Dec 10 '16 at 18:48
  • @GordonDavisson that killed the httpd that came with Apple but didn't resolve the localhost:8080, still have to access it via: 127.0.0.1:8080 It's strange – pixel 67 Dec 10 '16 at 19:09
  • @pixel67 That might be an IPv6 thing. localhost resolves to 127.0.0.1 (IPv4) *and* ::1 (IPv6) *and* fe80::1%lo0 (also IPv6), so if you have apache listening only on IPv4, localhost may not reach it. – Gordon Davisson Dec 10 '16 at 19:20
  • 127.0.0.1 localhost255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost – pixel 67 Dec 10 '16 at 19:27
  • that's the /ets/hosts file – pixel 67 Dec 10 '16 at 19:28
  • 2
    localhost can also resolve to an IPv6 address while 127.0.0.1 is guaranteed to be ipv4. Your application might behave differently ipv6 vs ipv4. – Jason Martin Dec 10 '16 at 21:44

1 Answers1

2

After installing httpd24 with brew you have two completely different Apache web server environments:

  1. brew's httpd24
  2. the original macOS/OS X httpd

Both have different config files and apachectl (and other) binaries. The first one is installed to /usr/local/Cellar/httpd24 and its binaries are linked to /usr/local/bin. macOS' httpd related binaries are located at /usr/sbin.

Depending on your PATH variable (enter echo $PATH to get it) sudo apachectl [cmd] either controls the first or the second Apache environment.

After installing brew the default PATH should be /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin which favors brew's httpd24. You can control macOS' Apache by using the full path (/usr/sbin/apachectl) though.

If you have a different path which doesn't favor /usr/local/bin over /usr/sbin it's the other way round. To get the path of the favored apachectl you can also simply enter which apachectl.

Check this with /usr/local/bin/apachectl -S which should yield:

VirtualHost configuration:
ServerRoot: "/usr/local/opt/httpd24"
Main DocumentRoot: "/usr/local/var/www/htdocs"
Main ErrorLog: "/usr/local/var/log/apache2/error_log"
Mutex default: dir="/usr/local/var/run/apache2/" mechanism=default 
Mutex mpm-accept: using_defaults
PidFile: "/usr/local/var/run/apache2/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="daemon" id=1 not_used
Group: name="daemon" id=1 not_used

and /usr/sbin/apachectl -S

VirtualHost configuration:
ServerRoot: "/usr"
Main DocumentRoot: "/Library/WebServer/Documents"
Main ErrorLog: "/private/var/log/apache2/error_log"
Mutex default: dir="/private/var/run/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex proxy: using_defaults
PidFile: "/private/var/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="_www" id=70 not_used
Group: name="_www" id=70 not_used

There are no mutually used files/folders.

They also use different standard config files:

/usr/local/bin/apachectl -t -D DUMP_INCLUDES
Included configuration files:
  (*) /usr/local/etc/apache2/2.4/httpd.conf

The command doesn't work properly for the original (macOS) apachectl though and only yields: Syntax OK.


If you run both httpds (configuring different ports here: 80: macOS; 8080 httpd24 - check this in the respective config files) ps -aef | grep httpd | grep -v grep will show the following:

  0    76     1   0  4:54pm ??         0:00.13 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
  1   219    76   0  4:54pm ??         0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
  1   220    76   0  4:54pm ??         0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
  1   221    76   0  4:54pm ??         0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
  1   222    76   0  4:54pm ??         0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
  1   223    76   0  4:54pm ??         0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
  1  4239    76   0  5:06pm ??         0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
  0  8251     1   0  5:45pm ??         0:00.08 /usr/sbin/httpd -D FOREGROUND
 70  8261  8251   0  5:46pm ??         0:00.00 /usr/sbin/httpd -D FOREGROUND

The first seven pids belong to httpd24, the last two to macOS' httpd - check the binary paths listed! and nmap localhost:

Starting Nmap 7.31 ( https://nmap.org ) at 2016-12-22 18:00 CET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00039s latency).
Other addresses for localhost (not scanned): ::1 fe80::1
Not shown: 499 closed ports, 498 filtered ports
PORT     STATE SERVICE
80/tcp   open  http
8080/tcp open  http-proxy

In your private chat message you can clearly see that httpd24 isn't running at all, but macOS' httpd is.

To disable macOS' httpd simply run sudo /usr/sbin/apachectl stop and additionally sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist (just to be sure).

Then dump the brew service start ... method by stopping the service and installing a real plist daemon like recommended in the linked how-to.

sudo cp -v /usr/local/Cellar/httpd24/2.4.23_2/homebrew.mxcl.httpd24.plist /Library/LaunchDaemons
sudo chown -v root:wheel /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
sudo chmod -v 644 /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist

Reboot. If you still get an error connecting with localhost:8080 to your local developer site comment out fe80::1%lo0 localhost in /etc/hosts. In my environment it works with this line though.


After further investigations it turns out that a misconfigured web proxy (part of ESET's Internet Security/Antivirus) is the culprit. By adding a proper localhost exclude it should be possible to solve the problem.

klanomath
  • 167
  • 1
  • 1
  • 5
  • Thanks for helping out, I tried your commands, [here](https://gist.github.com/anthonybrown/6b97c39d3277c3a012eda42cdd5911ee) is the outputs of the commands in order that you wrote them. – pixel 67 Dec 25 '16 at 10:45
  • I used the `--privileged-port` as well I'm almost ready to do a clean install – pixel 67 Dec 25 '16 at 13:57
  • I don't have dnsmasq running, although I did play around with getting it setup awhile back. I did not perform mDBSResponder cache – pixel 67 Dec 25 '16 at 14:09
  • @klonomath [here](https://gist.github.com/anthonybrown/2299cf66bd728df5a79a94b5c551bf31) is a gist of what's running – pixel 67 Dec 25 '16 at 14:11
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/50682/discussion-between-pixel-67-and-klanomath). – pixel 67 Dec 25 '16 at 14:16