How do I setup a localhost using the Sites folder on my Mac?

Solution 1:

The web sharing checkbox was removed in 10.8, but sudo apachectl start also enbales the launchd agent permanently (see cat /usr/sbin/apachectl). To make http://localhost/~username/ work, you can save something like this as /etc/apache2/users/username.conf:

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

If you want to direct localhost to ~/Sites/, you can change DocumentRoot in /etc/apache2/httpd.conf.

You can add a virtual host by uncommenting Include /private/etc/apache2/extra/httpd-vhosts.conf in /etc/apache2/httpd.conf, adding 127.0.0.1 testsite.dev to /etc/hosts, and adding this to /etc/apache2/extra/httpd-vhosts.conf:

<VirtualHost *:80>
    DocumentRoot "/Users/username/Sites/testsite/"
    ServerName testsite.dev
</VirtualHost>

sudo apachectl restart applies changes.

Solution 2:

Open System Preferences » Sharing, and enable Web Sharing.

On Mountain Lion Web Sharing has been removed from preferences, so use sudo apachectl start to start Apache.

You'll find the URLs specified there. For example, my Sites folder /Users/danielbeck/Sites is accessible as http://10.0.1.2/~danielbeck/.

Solution 3:

Here's a link to a great Step by step guide, on how to setup Apache, PHP and MySQL locally using the Sites folder.

http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion

It's geared towards Mountain Lion (10.8) but I'm sure it's adaptable to your needs.