Sunday
Feb192012

Enable Web Sharing on OS X without using Sharing Preference Pane

Let’s imagine that you could not enable “Web Sharing” from the System Preferences panel in OS X.

How would you do it?

Step One

First, make sure that these two files exist:

  • /usr/libexec/apache2/mod_bonjour.so
  • /usr/libexec/apache2/mod_userdir_apple.so

If they don’t exist, try copying them from an installation of Mac OS X 10.7.

(Why wouldn’t they exist? I can’t say. But it might happen.)

Step Two

Then you will need to edit the /System/Library/LaunchDaemons/org.apache.httpd.plist file to look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<true/>
<key>Label</key>
<string>org.apache.httpd</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
    <string>/usr/sbin/httpd</string>
    <string>-D</string>
    <string>FOREGROUND</string>
    <string>-D</string>
    <string>WEBSHARING_ON</string>
</array>
<key>SHAuthorizationRight</key>
<string>system.preferences</string>
</dict>
</plist>

Yes, it seems strange to set ‘Disabled’ to ‘true’ but that’s how it is supposed to be. I believe this is basically a deprecated setting.

See the next step for more information.

Step Three

Load the new plist via:

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

According to man launchctl:

-w      Overrides the Disabled key and sets it to false. In previous versions, this option would modify the configuration file. Now the state of the Disabled key is stored elsewhere on-disk.

Step Four

You may also need to create files for each user, such as /etc/apache2/users/luomat.conf (my short login name is luomat) which look like this:

<Directory "/Users/luomat/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

The relevant permissions:

drwxr-xr-x  7 root  wheel  238 Jan 10 10:03 /etc/apache2/users/

and for the user config files:

-rw-r--r--  1 root  wheel  142 Oct 14 16:41 /etc/apache2/users/luomat.conf

Step Five

Reboot the system and make sure that it still works.

« Use KeepAlive and launchd to keep apps alive | Day One and Terminal or Keyboard Maestro for quick activity logging »