Why is brew always reporting success when failing to start a service?

I'm trying to setup httpd with HomeBrew on a mac.

As I painfully learned today, brew services start always reports success, even when httpd fails to start.

Example failures reported as success:

  • failure to start httpd because another instance (started outside of brew) is already running;
  • failure to start httpd because of a syntax error in a config file

For example, say I deliberately put some random chars in httpd.conf, and run:

$ sudo brew services restart httpd

Brew happily reports success:

==> Successfully stopped `httpd` (label: homebrew.mxcl.httpd)
Warning: Taking root:admin ownership of some httpd paths:
  /usr/local/Cellar/httpd/2.4.41_1/bin
  /usr/local/Cellar/httpd/2.4.41_1/bin/httpd
  /usr/local/opt/httpd
  /usr/local/opt/httpd/bin
  /usr/local/var/homebrew/linked/httpd
This will require manual removal of these paths using `sudo rm` on
brew upgrade/reinstall/uninstall.
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)

Even though httpd is obviously not running:

$ sudo ps -A |grep httpd
 9481 ttys000    0:00.01 grep httpd
 (nothing else)
$ sudo lsof -iTCP:80 -sTCP:LISTEN
 (nothing)

What's wrong? Is this a bug in brew?


Trying to debug Apache issues on any computer can be difficult, but you just have to know what commands and files to look at. First, try to start Apache using the apachectl command and look for errors written to the screen.

$ sudo apachectl start

If there is an error in the apache conf files or some system issue, you may see it there.

Also, you need to review the log file and see what the service is writing about itself. For homebrew, the log file is typically called -

/usr/local/var/log/httpd/error_log

Often, when I find that Apache won't start, it is because there is a pid lock file that makes Apache think another instance is already running and you will see this in the log file. Delete the lock file and try to start the service again.

/usr/local/var/run/httpd/httpd.pid

One final note, a great resource for using homebrew to get a LAMP environment up and running on OSX is from Andy Miller over on getgrav.org (https://getgrav.org/blog/macos-catalina-apache-multiple-php-versions). Follow those instructions and you're ready to go..