Map "Sites" folder to http://localhost on OS X

You want to change the "DocumentRoot" setting in the file /etc/apache2/httpd.conf, and restart web sharing.


Go to /etc/apache2/httpd.conf

Find

DocumentRoot  "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">

Change it to:

DocumentRoot "/Users/bob/Sites"
<Directory "/Users/bob/Sites">

Where bob is your username. Now you can access localhost/mywebsite instead of localhost/~bob/mywebsite

You might need to restart apache sudo apachectl restart


I have also just changed DocumentRoot in /etc/apache2/httpd.conf. But another option is to use vhosts:

  1. Uncomment Include /private/etc/apache2/extra/httpd-vhosts.conf in /etc/apache2/httpd.conf
  2. Add this to /etc/apache2/users/username.conf or /etc/apache2/extra/httpd-vhosts.conf:

    <VirtualHost *:80>
        DocumentRoot "/Users/username/Sites"
        ServerName localhost
    </VirtualHost>
    
  3. sudo apachectl restart

If you get an error like You don't have permission to access / on this server, try adding this to /etc/apache2/users/username.conf:

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