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

29,828

Solution 1

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

Solution 2

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

Solution 3

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>
Share:
29,828

Related videos on Youtube

Sindre Sorhus
Author by

Sindre Sorhus

Updated on September 17, 2022

Comments

  • Sindre Sorhus
    Sindre Sorhus almost 2 years

    I'm using the built-in server on my Mac.

    The URL to my Sites folder is: http://localhost/~username/

    with MAMP I had just http://localhost/.

    Is there any way to get just http://localhost/ with the built-in server?

    I have only one user account on my Mac.

    • Admin
      Admin over 5 years
      I am using the localhost/~username. Is there a way to access it with the IP address. Currently when i access it with IP adress, I get Forbidden You don't have permission to access /~username/ on this server.
  • Sindre Sorhus
    Sindre Sorhus almost 15 years
    I want to have the files in the Sites folder, can I create an hardlink/symlink or something?
  • Christian Studer
    Christian Studer almost 15 years
    Yes, you can. But do it in the Terminal, the Finder doesn't really create real hard/symlinks.