Article:
  Location, Location, Location: Tips for Storing Web Site Files
Subject:   Use NetInfo Manager instead of /etc/hosts and other comments
Date:   2003-05-17 15:34:05
From:   maarky
For me it's easier to open NetInfo Manager rather that looking for a hidden file. So instead of directly editing your /etc/hosts file you can go to /Applications/Utilities/NetInfo Manager


Once you launch NetInfo Manager you will click on "machines" and then "localhost". Now you want to click on the lock in the bottom left corner so that you can edit the info (must be an admin user). Now duplicate "localhost" and rename the duplicate whatever you want your virtual host to be named. So for instance, you change "localhost copy" to "test.icalshare.com".


Now deselect your new machine by clicking on another one. It will ask you if you really want to make the change. Say yes. There you go.


Another thing. I don't know the wisdom of this but I got it from the apache documentation ( http://httpd.apache.org/docs/vhosts/name-based.html ) and I have had no issues with it. You do not need to specify 127.0.0.1 in your virtual host directives. All you need is "*". For example, the following should work just fine:


NameVirtualHost *


<VirtualHost *>
DocumentRoot /Users/patrick/Documents/Projects/iCalShare/wwwroot
ServerName test.icalshare.com
</VirtualHost>


You can also add other directives inside your virtual host directive. For example, do you want each of your virtual hosts to have its own php include path? Do you want to add a domain specific alias? If so do this:


<VirtualHost *>
DocumentRoot /Users/patrick/Documents/Projects/iCalShare/wwwroot
ServerName test.icalshare.com
<IfModule mod_php4.c>
php_value include_path "Users/patrick/Documents/Projects/iCalShare/"
</IfModule>
Alias /manual/ "/Library/WebServer/Documents/manual/"
<Directory "/Library/WebServer/Documents/manual">
Options FollowSymlinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


There's plenty of other stuff you can put in there too.


I have also noticed that with these virtual hosts they are case sensitive. Taking the above example, "http://test.icalshare.com" will work, but "http://test.iCalShare.com" will not. Also, if you name you virtual host "php.mac" then "http://php.mac" will work, but "http://www.php.mac" will not. But if you name your virtual host "www.php.mac" then the opposite is true.


As a side note I have gone kinda crazy with virtual hosts since getting os x. I downloaded the PHP documentation Web pages and made a virtual host for that and the same for mysql documentation, phpmyadmin and so on. The convention I have used for tld's is .mac There is no .mac tld so I don't have to worry about it conflicting with real domains. So, if I want my php documentation I go to "http://php.mac"

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • Re: Use NetInfo Manager instead of /etc/hosts and other comments
    2003-05-19 14:10:10  icalshare [View]

    Good idea on using NetInfo Manager -- that sounds much easier, especially for people who prefer a GUI option.

    ...

    As for using 'NameVirtualHost *', yes, this works fine if you only intend to use one virtual host.

    But, if you wish to use several hosts, and more importantly, wish to use other projects in your Sites folder *without* using Alias or VirtualHost, this will not work.

    We need to explicitly name 127.0.0.1, or otherwise Apache sends us straight to the virtual host.

    Best,
    Patrick