I'm on a fresh 10.9 install and the default Apache server is org.apache.httpd: Already loaded after each startup. Is there a way to disable that autostart?
1 Answers
OS X provides launchctl to control which daemons are started at boot time.
To stop and disable Apache:
- Open Terminal
Type the following command (type your login password when
sudorequests 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.
-
I tried that, but each time I run `sudo apachectl start` the launch daemon seems to be activated again after restart. – Till Feb 04 '14 at 08:14
-
Try with `-w`: `sudo launchctl -w unload ...`. If it doesn't help, could you post the output of `ps -ef|grep httpd|grep -v grep`? – jaume Feb 04 '14 at 08:27
-
I tried `-w` before, same result. Here is the output: http://pastebin.com/h14t8fEv – Till Feb 04 '14 at 15:05
-
Thanks, does `sudo launchctl1 ...` return an error message? Could you post the output of `grep apache /var/log/com.apple.launchd/launchd-shutdown.system.log` and `sudo grep apache /var/log/system.log`? – jaume Feb 04 '14 at 15:56
-
Yes: `sudo: launchctl1: command not found` and here is the output: http://pastebin.com/raw.php?i=zxKvYV4i – Till Feb 05 '14 at 07:33
-
Sorry, I made a typo, I meant `sudo launchctl...` and not `sudo launchctl1...`, but I've seen that `launchctl` works as expected, thanks for posting the output. Apache is indeed started by `launchctl` when OS X starts up, the PPID is 1, so "something" re-enables it. Do you have other software, like "OS X Server" (https://itunes.apple.com/us/app/os-x-server/id714547929?mt=12), that requires Apache? – jaume Feb 05 '14 at 07:53
-
No, it's a fresh install and the only thing I've got installed that could start Apache is Xcode. I remember reading a while ago that `apachectl start` registers the launch daemon. Maybe the best thing to do is execute `launchctl unload` on shutdown? – Till Feb 06 '14 at 12:05
-
That's the key, `apachectl start` starts Apache and modifies `/private/var/db/launchd.db/com.apple.launchd/overrides.plist` to **enable** it in a similar way `launchctl` does (http://superuser.com/questions/455505/how-do-i-start-apache-in-osx-mountain-lion). Try `apachectl stop`, it should stop **and** disable it for good. – jaume Feb 06 '14 at 15:37
-
Great, thanks for your feedback, I edited my answer to add information on `apachectl`. Option `-w` would have worked too (at least it worked for me), unfortunately the command I told you to type (`sudo launchctl -w unload ...`) was wrong, the correct syntax is `sudo launchctl unload -w ...`. – jaume Feb 07 '14 at 08:18