[thelist] Set up a localhost on Mac OSX?

Steve Axthelm steveax at pobox.com
Fri Oct 5 14:21:51 CDT 2007

On 2007-10-05 Barney Carroll wrote:

>What's the simplest way of setting up a virtual host? Have no 
>frameworks installed or in mind.

If all you want is for the local machine to be able to access 
the virtual host it's pretty easy to set up name-based virtual 
hosting using the built in Apache. You'll need to make additions 
to two files (this assuming 10.4.x):


(<username> being the active user's 'short name')

Add the NameVirtualHost directive and a VirtualHost block like 
below but with the paths pointing to the directories you want to 
serve out of.

Notice that the DocumentRoot line does not have a trailing slash 
but the opening of the directory block does.

------------- start -----------------------------------------
NameVirtualHost *:80

<VirtualHost *:80>
     ServerName dz.local
     DocumentRoot /Users/steve/assets/sites/dz/project
     <Directory /Users/steve/assets/sites/dz/project/>
         Options ExecCGI FollowSymLinks
         AllowOverride all
         Allow from all
         Order allow,deny
------------- end -----------------------------------------

Then open /etc/hosts and add this to the bottom of the file:  dz.local

Restart Apache ('sudo apachectl restart' from a terminal window 
or use the Sharing Preference Pane) and 'dz.local' in a web 
browser should open up the content in the directory specified in 
the VirtualHost block.



Steve Axthelm
steveax at pobox.com

More information about the thelist mailing list