X

How to enable Web Sharing in OS X Mountain Lion

In OS X Mountain Lion, Apple has removed the option for personal Web sharing; however, this feature can be enabled if needed.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
4 min read

The Sharing services in OS X allow for a number of connectivity options, including screen sharing, file sharing, printer sharing, and the capability to use your computer as an Internet router. In past versions of OS X, Apple has also included a full Web sharing service using the open-source Apache server that allows you to host Web pages on your computer, but this option has been removed from the system preferences in Mountain Lion.

Despite its relative lack of popularity, the presence of the full Apache Web server in OS X has been useful for testing Web development projects, or setting up a small workgroup Web server.

Missing Web Sharing in Mountain Lion
The Web Sharing feature in OS X is missing from Mountain Lion's Sharing system preferences. Screenshot by Topher Kessler/CNET

While Apple may have removed the configuration settings for the Web server in the system preferences, the Apache server is still included in Mountain Lion and can be enabled for those who need it. The steps for enabling this include optionally configuring the server for hosting Web pages in the "Sites" folder in your home directory, and then enabling the server itself.

Optionally enable user Web sites
By default the Apache Web server will issue Web sites that are stored in your system's global Web server folder (/Library/Web Server/Documents), which are accessed by typing "http://localhost/" in a Web browser. However, if you try to access Web sites in your personal sharing folder by appending "~username" to the end of the URL then you will get "Forbidden" error in the Web browser. While you can use the global Web server folder for your sites, for convenience you can enable your home folder's site by creating an Apache user configuration file like the one created in prior versions of OS X when personal file sharing is enabled:

  1. Open the OS X Terminal utility (/Applicaitions/Utilities/)
  2. Create and edit an Apache user configuration file named after your user account by running the following command.

    sudo pico /etc/apache2/users/`whoami`.conf

  3. Copy the following text into the Terminal editor that opens, but be sure to change the "username" text to the short name of your user account:

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

  4. Save and close the editor by pressing Control-O followed by Control-X.

After this action is performed, create a folder called "Sites" in your home directory if it is not already present, and then place your Web pages within it.

Enabling the server
To enable the Web server you have two options. The first is to temporarily start it using the following "apachectl" terminal command (to disable the server, repeat the command with "stop" instead of "start"):

sudo apachectl start

OS X Web server firewall warning
When you enable the Web server you will see this warning appear, so be sure to allow connections if you plan on serving pages to other computers. Screenshot by Topher Kessler/CNET

Note that since Web sharing is not in the Sharing system preferences, it is no longer considered an essential system service so the OS will not automatically configure the firewall for it. Therefore when you enable it, you will be asked to allow the Web server process (httpd) to allow incoming connections. If you plan on using the server as a test server for your computer, only then do you not need to allow connections through the firewall; however, if you want to host pages for other computers to see, then you will need to allow connections.

Keep in mind that the steps so far will only keep the server running while the system is booted, so if you restart then the server will be disabled again. To enable the server even after subsequent reboots, then you will need to enable the launch daemon for the server, which can be done with the following command:

sudo defaults write /System/Library/LaunchDaemons/org.apache.httpd Disabled -bool false

As with the previous command, this one can be reversed by repeating it but changing the "false" text to "true."

This procedure will enable the server and allow you to host Web pages, but will not enable any additional Web technologies like SQL or PHP. If you need these, then they can be installed and enabled separately following the instructions in the guide by Coolest Guy Planet Tech.

After the server is running, if you still see errors when accessing Web pages in your home folder (ie, with the url "http://localhost/~username"), then be sure the file (and any others you may have configured) are properly accessible by running the following two Terminal commands to alter their ownership and permissions:

sudo chown root:wheel /etc/apache2/users/*
sudo chmod 644 /etc/apache2/users/*

When the configuration file's permissions have been set, run the following command to restart the server and load the file again before attempting your connections:

sudo apachectl restart


Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.