0

I am creating this question because this problem caused me 2 weeks of headache, and I found many other users online who experienced the same issue and were unable to find a solution.

Computer

M1 macbook running Sonoma or Monterey. This may affect other Apple Silicon macbooks as well.

Background

I installed homebrew and used this to install httpd and php. Prior to any configuration, I ran brew services start httpd to test this out. Under normal circumstances, you can then visit localhost:8080 which should show a blank page with It Works!

In my case, it showed that the page could not be reached.

A major symptom of this issue is that the error_log will be showing outdated logs or no logs at all which causes difficulties when searching for the solution.

Troubleshooting

I ran brew services list which showed that httpd was experiencing Error 256:

brew services list
Name  Status     User            File
httpd error  256 georgeciesinski ~/Library/LaunchAgents/homebrew.mxcl.httpd.plist

Checking Error Log

I checked the error log by running:

tail -f /opt/homebrew/var/log/httpd/error_log

As I mentioned earlier, this specific problem is caused by httpd being unable to access the error log. This results in log messages showing outdated logs from hours ago even if you ran brew services start httpd minutes before. It may also show no logs at all.

Failed Solutions

I tried many things to fix this problem before finding the working solution.

  • Starting Apache with sudo apachectl start
  • Checking which -a httpd I have installed which showed the brew and apple installations
  • Searching which config is used by httpd
  • brew reinstall httpd and brew reinstall php

1 Answer 1

0

Solution

httpd command

I found a discussion on the homebrew github that suggested to run:

brew info httpd

This shows a long output, but the key text is:

To restart httpd after an upgrade: brew services restart httpd Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND

Some users in the discussion also suggested to try running this command:

/opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND

This resulted in the first informative error message so far:

(13)Permission denied: AH00091: httpd: could not open error log file /opt/homebrew/var/log/httpd/error_log.

Check Permissions

First cd into the httpd log folder:

cd /opt/homebrew/var/log/httpd/

and then check permissions

ls -al

-rw-r--r-- 1 root admin 29727 20 May 19:13 access_log -rw-r--r-- 1 root admin 22508 20 May 19:17 error_log

This indicates that the root user has read and write permissions to the access_log and error_log, but the group and others only have read permissions.

Apache uses either the apache or httpd user when running, but I could not figure out which one to change ownership to. I kept looking and found this post which shows how to change the permissions to 666 (or -rw-rw-rw-: read and write for user, group, and others) so that it can stay under root ownership but the apache user can still write to the files.

sudo chmod 666 error_log
sudo chmod 666 access_log

Test solution

I recommend opening one terminal window and tail error_log first:

tail -f /opt/homebrew/var/log/httpd/error_log

In a second terminal window, run:

/opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND

The error_log should now repeat this command indicating httpd is now able to write to it. Click ctrl + c in the second window to stop httpd.

Next, try running it as a service again:

brew services start httpd

Following this, check if the error is resolved:

brew services list

httpd started georgeciesinski ~/Library/LaunchAgents/homebrew.mxcl.httpd.plist

If it starts with httpd started then httpd is now able to access the error_log and the problem should be resolved.

Try restarting the computer and run brew services list once again to ensure that it is working.

Also, you can go to localhost:8080 and it should say "It's Working!"

You must log in to answer this question.

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