Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

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/.

share|improve this answer
    
Thank you, but I wanted to get local php working such as WordPress. I have seen many posts, but none about the "Sites" folder. –  david Dec 24 '10 at 0:41
    
@david In that case, your question is lacking your actual requirements. You need to configure Apache to support PHP, just as on any other system. httpd.conf is in /etc/apache2, and while it's been a while since I worked with it, you might have success by uncommenting the line containing php5_module, and toggling Web Sharing to restart Apache. –  Daniel Beck Dec 24 '10 at 0:44

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.

share|improve this answer

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.

share|improve this answer
1  
please do no use links as answers, it is strongly disencouraged. if the link gets broken, so does your whole answer. instead, try elaborating a consistent answer with relevant data from the link and post the same link as reference. –  Lorenzo Von Matterhorn Mar 14 '13 at 3:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.