10

I've switched out the default apache for the homebrew version. I've stopped the default apache starting on boot with:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

However, the homebrew version does not start automatically. The httpd process is running (as confirmed by brew services start httpd) but the server is not running, until I execute

sudo apachectl start

(apachectl here refers to the homebrew version at /usr/local/bin/apachectl)

I'm using macOS Mojave, and the homebrew Apache version is 2.4.37.

3 Answers 3

12

If you run:

brew services

The last two lines of the output gives the answer to your question:

If sudo is passed, operate on /Library/LaunchDaemons (started at boot).
Otherwise, operate on ~/Library/LaunchAgents (started at login).

So, to start apache at boot run:

sudo brew services start apache2

and to start apache at login run:

brew services start apache2
0
3

I tried the accepted solution, but it didn't worked for me. The only way to get the autostart to work was by modifying the '.plist' file:

sudo brew services start apache2
sudo nano /Library/LaunchDaemons/homebrew.mxcl.httpd.plist

I added:

<string>/usr/local/bin/apachectl</string>
<string>start</string>

And I also commented out:

<string>/usr/local/opt/httpd/bin/httpd</string>
<string>-D</string>
<string>FOREGROUND</string>

The result looked like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>homebrew.mxcl.httpd</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/bin/apachectl</string>
    <string>start</string>
    <!--
    <string>/usr/local/opt/httpd/bin/httpd</string>
    <string>-D</string>
    <string>FOREGROUND</string>
    -->
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>
1
  • Perfect. What this also solved for me was that httpd was always started under the wrong user, so after a reboot I'd have to kill it and then start it with the correct user. Commented Nov 1, 2023 at 12:15
0

Instead of apache2 I had to use httpd :

brew services restart httpd

This was on my MacBook Air M2 with Sonoma and Apache 2.

Even on my macOS Mpjave its httpd and not apache2.

$ brew services start httpd
Error: Formula `httpd` is not installed.
$ brew services start apache2
Error: Formula `httpd` is not installed.
4
  • 1
    This question is for “macOS Mojave and Apache version 2.4.37.” is that your setup?
    – bmike
    Commented Jun 7 at 2:12
  • I do have a macOS Mojave and Apache version 2.x but I tested this on a MacBook Air with Sonoma and Apache 2
    – anjanesh
    Commented Jun 7 at 3:57
  • 2
    Nice. Editing that in might help others know it’s relevant due to the time passed…
    – bmike
    Commented Jun 7 at 4:07
  • Would brew have had changed from apache2 to httpd during the time period since Mojave ?
    – anjanesh
    Commented Jun 7 at 4:10

You must log in to answer this question.

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