Women in Technology

Hear us Roar



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"

Full Threads Oldest First

Showing messages 1 through 3 of 3.

  • 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
    • Re: Use NetInfo Manager instead of /etc/hosts and other comments
      2003-05-20 16:28:39  maarky [View]

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

      I use 'NameVirtualHost *' and yet I have no problems despite having set up 12 virtual hosts. From my experiences explicitly naming 127.0.0.1 is not necessary. I could be overlooking something, but it does not seem to be affecting any aliases, though the only ones I have are the standard icons and manual aliases which are there by default and they work fine in all of my virtual domains.

      You mentioned there would be problems using "other projects in your Sites folder *without* using Alias or VirtualHost". What do you mean by this? I don't have any problems with the sites folders in /Library/WebServer/Documents or /Users/userName/Sites by going to localhost or localhost/~username. If we don't specify 127.0.0.1 which virtual host are we sent to? Am I missing something because everything at least seems to be working just fine for me.

      Thanks
      • Re: Use NetInfo Manager instead of /etc/hosts and other comments
        2003-05-23 12:39:31  anonymous2 [View]

        I'm also using "NameVirtualHost *" without problems; I'm hosting a couple of real web sites on my Cube, connecting via an Airport base to internet.

        One additional thing: Since Apple updates often overwrites http.conf, add

        Include /private/etc/httpd/virtual.conf

        at the bottom of httd.conf and add all virtual host settings in this file like this:

        NameVirtualHost *

        <VirtualHost *>
        ServerName "www.wigzell.net"
        DocumentRoot "/Library/WebServer/Documents"
        </VirtualHost>

        <VirtualHost *>
        ServerName "www.wigzell.se"
        DocumentRoot "/Library/WebServer/wigzell.se"
        </VirtualHost>

        Using this, you only have to re-add the first line after a system update