70

OSX Mountain Lion removed the GUI for web sharing, but apache is still installed.

How do I start and stop the service? How do I get the service to automatically launch on startup?

slifty
  • 1,569
  • 1
  • 13
  • 18

6 Answers6

77

The LaunchDaemon for Apache is still there as well, so all you have to do it load it:

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

The -w makes it permanent, i.e. it'll be reloaded when you reboot.

Gordon Davisson
  • 34,084
  • 5
  • 66
  • 70
  • How do you turn this off once it's started this way? – James McMahon Sep 05 '12 at 14:13
  • 9
    @JamesMcMahon: `sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist` – Gordon Davisson Sep 05 '12 at 14:14
  • Hmm, something is still running on localhost, I had assumed it was Apache, maybe I have something else running. – James McMahon Sep 05 '12 at 14:19
  • @JamesMcMahon: You can use e.g. `sudo lsof -i:80` to see what process is listening on a given port. From there, [this previous answer](http://serverfault.com/questions/285078/how-can-i-prevent-a-process-from-running-under-mac-osx-10-6/285088#285088) might help you track it down... – Gordon Davisson Sep 05 '12 at 14:58
35

Terminal Commands

Starting: "sudo apachectl start"

Stopping: "sudo apachectl stop"

Restarting: "sudo apachectl restart"

Launching on Startup

(See the marked answer in this thread)

slifty
  • 1,569
  • 1
  • 13
  • 18
12

sudo apachectl start also enables the launchd daemon. It overrides the Disabled key in /System/Library/LaunchDaemons/org.apache.httpd.plist by modifying /private/var/db/launchd.db/com.apple.launchd/overrides.plist, just like launchctl load -w.

For http://localhost/~username/ to work, you have to create /etc/apache2/users/username.conf and add a <Directory> directive like this:

<Directory "/Users/username/Sites/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Lri
  • 40,894
  • 7
  • 119
  • 157
  • 1
    I found a really great writeup of this, here. Also covers php module enablation. http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion – Peter Ehrlich Oct 13 '12 at 19:35
8

Slifty and Lauri hint at an important concept without clearly saying it.

"sudo apachectl start" will not only start apache but will also modify /private/var/db/launchd.db/com.apple.launchd/overrides.plist so that apache will automatically restart each time the system is rebooted.

Similarly, "sudo apachectl stop" will stop apache and modify the above file so that apache won't start when the system is rebooted.

This seems to be the simplest way to control whether the service starts automatically.

aeropapa17
  • 181
  • 1
  • 2
3

For those in search of a GUI, Click On Tyler has developed a control panel app, http://clickontyler.com/blog/2012/02/web-sharing-mountain-lion/

GUI sample

James McMahon
  • 3,438
  • 9
  • 36
  • 36
1

This preference pane has the links for computer site folder and to open a browser : http://stowlake.com/WebServer

  • This rather ugly UI's preference panel crashes immediately as you try to start the web-server on both OS-X 10.11 and 10.12. Crash-logs available at your request ;) – Motti Shneor Nov 16 '16 at 08:53