MacOS – How to get the user directory working for web sharing again

apachemacosweb-sharing

I had web sharing enabled in Lion and a web site at http://localhost/~user, where user is my User directory. When I upgraded to Mountain Lion, web sharing (Apache) remained enabled and I can go to localhost and get the "It works!" default web page, but I cannot access my user page anymore. The error is

Forbidden

You don't have permission to access /~user/ on this server.

How do I re-enable my user directory's web page?

Best Answer

Here is how you can re-enable the web page with the command line using Terminal.

First copy this and paste it into Terminal. You may have to press enter after pasting to run it. It will ask for your password because it is adding a file to your system directory.

USER_DIR=$(basename $(echo ~))
sudo bash -c "cat > /etc/apache2/users/$USER_DIR.conf" <<TEXT
<Directory "/Users/$USER_DIR/Sites">
     Options Indexes MultiViews
     AllowOverride None
     Order allow,deny
     Allow from all
</Directory>
TEXT

Then run this command to restart the web server:

sudo apachectl restart