Disable Apache autostart

Solution 1:

OS X provides launchctl to control which daemons are started at boot time.

To stop and disable Apache:

  1. Open Terminal
  2. Type the following command (type your login password when sudo requests it):

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

A few words on launchctl's -w option

The -w option is the silver bullet for stopping/disabling Apache. It tells launchctl to do its job regardless of any configuration settings that would otherwise prevent it from unloading the service, as explained in man launchctl:

-w       Overrides the Disabled key and sets it to false or true for the load and
         unload subcommands respectively. In previous versions, this option would
         modify the configuration file. Now the state of the Disabled key is stored
         elsewhere on- disk in a location that may not be directly manipulated by any
         process other than launchd.

(It turns out that, in OS X Mavericks (10.9), "elsewhere on-disk" is /private/var/db/launchd.db/com.apple.launchd/overrides.plist.)

The -w option is indispensable if you started Apache with apachectl start: as explained in this Superuser answer. apachectl not only starts Apache but also modifies /private/var/db/launchd.db/com.apple.launchd/overrides.plist like this:

<key>org.apache.httpd</key>
<dict>
        <key>Disabled</key>
        <false/>
</dict>

In this particular case you can also use apachectl:

sudo apachectl stop

to stop Apache and to set Disabled to true.