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

6

4

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.

Sindre Sorhus

Posted 2009-09-05T15:51:51.387

Reputation: 363

I am using the http://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.

– Kuldeep Bhimte – 2019-02-23T06:40:03.307

Answers

5

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

Richard Hoskins

Posted 2009-09-05T15:51:51.387

Reputation: 10 260

5

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

Mirror318

Posted 2009-09-05T15:51:51.387

Reputation: 151

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>

Lri

Posted 2009-09-05T15:51:51.387

Reputation: 34 501

0

I also wanted to move the local host files to an external hard drive.

The issue I had was spaces in the hard drive name or folder name. No matter what I added +Space it would not work. It did however work when I changed the hard drive and folder name removing the space(s) and then mapping it something like:

DocumentRoot "/Volumes/HDD_NAME/WebServer/Folder_Name"

So now Dreamweaver or other edit is mapped to the external hard drive and the http.conf file is mapped to the external hard drive saving 100GB of my small internal hard drive's space. Of course, this means I can only edit and test locally with that external hard drive attached.

Mike Rooch

Posted 2009-09-05T15:51:51.387

Reputation: 1

0

You need to put your site in /Library/WebServer (not sure about WebServer part but it should be similar) and make sure permissions are correct.

churnd

Posted 2009-09-05T15:51:51.387

Reputation: 4 228

I want to have the files in the Sites folder, can I create an hardlink/symlink or something? – Sindre Sorhus – 2009-09-05T17:13:40.643

Yes, you can. But do it in the Terminal, the Finder doesn't really create real hard/symlinks. – Christian Studer – 2009-09-16T11:43:54.057

0

The best way to do this, which I've already done is this terminal command (first delete, rename or move the Documents folder out of /Library/WebServer): ln -s ~/Sites/ /Library/WebServer/Documents.

mk12

Posted 2009-09-05T15:51:51.387

Reputation: 2 432