This small AppleScript can be placed in the Dock, allowing one-click launching and terminating of Apache. One caveat: In order for this to work, you have to edit /etc → sudoers to give yourself the ability to launch Apache without having to enter your password – see man sudoers for help with that process. That’s a potential security risk, but as I see it, it’s no riskier than allowing System Prefs to launch it via a button.
OS version: OS X
do shell script "sudo /usr/sbin/apachectl stop"
if result = "/usr/sbin/apachectl stop: httpd (no pid file) ¬
not running" then
do shell script "sudo /usr/sbin/apachectl start"
display dialog "Apache Started" with icon 2 buttons ¬
{"OK"} giving up after 1
else
display dialog "Apache Stopped" with icon 2 buttons ¬
{"OK"} giving up after 1
end if