Using default OSX apache httpd to serve ~/Sites/foo at http://foo.local
By configuring dns and using virtual hosts - you can automatically serve folders in your ~/Sites directory under a local domain.
Wildcard DNS is a better option that editing your /etc/hosts file for every site, there are a few ways to do this.
http://mikeferrier.com/2011/04/04/setting-up-wildcard-dns-on-localhost-domains-on-osx/
in our office - *.ben.dev points to my machine.
If you have a spare domain kicking about, you can point it back to 127.0.0.1 (for example ping foo.lvh.me
) and use that.
edit /etc/apache2/extra/httpd-vhosts.conf
, remove examples and add:
<VirtualHost *:80>
ServerName local
ServerAlias *.local
UseCanonicalName Off
VirtualDocumentRoot /Users/ben/Sites/%1
DirectoryIndex index.html
<Directory /Users/ben/Sites>
Options Indexes SymLinksIfOwnerMatch
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
(changing /Users/ben/Sites/%1
to your own)
uncomment this line in /etc/apache/http.conf
#Include /private/etc/apache2/extra/httpd-vhosts.conf
sudo apachectl restart
mkdir ~/Sites/test
echo "<h1>Howdy</h1>" > ~/Sites/test/index.html
open http://test.local/
Cheers Ben, this has done exactly what I needed!