Virtual hosts on Mac OS X Leopard

The instructions in The Essential Guide to Dreamweaver CS3 and Foundation PHP for Dreamweaver 8 were written before the release of Mac OS X 10.5 (Leopard). Revised instructions for setting up virtual hosts on Leopard can now be found in the Tutorials section of my website.

This entry was posted in Apache, Books, Dreamweaver. Bookmark the permalink.

15 Responses to Virtual hosts on Mac OS X Leopard

  1. Anne-Marie says:

    Hi David,

    i’m just starting your book; php solutions! I’ve a new imac with leopard installed; I’m trying to open the php.ini settings but I can’t get in the directory in the terminal; I get this message:

    anne-marie-van-dongens-imac:~ myusername$ CD/private/etc
    -bash: CD/private/etc: No such file or directory

    i’m trying to find an answer on the different forums but maybe you could help me out as well?? thanks,
    Anne-marie

  2. David Powers says:

    There should be a space between cd and /private. cd is a command that means “change directory”.

  3. Peter says:

    This won’t work for multiple sites will it, by that I mean if I have 100 sites, eg http://clientsiteone/ http://clientsitetwo/ that wouldn’t work with this method because whichever comes first such as 127.0.0.1 clientsiteone will hijack the path of any

    DocumentRoot “/Library/WebServer/Documents”
    ServerName clientsiteone

    after right?

    Would you agree that using aliases is the best option here, like:

    Alias /clientsiteone “/Users/me/Sites/clients/clientone/clientsiteone/www”

    then the url is http://localhost/clientsiteone/

    Is there a better way?

  4. David Powers says:

    Peter, my instructions will work for multiple sites.

  5. Edward says:

    Hi David,

    I have been enjoying your EGDWCS3 book for several months now – thank you for writing it! Before upgrading to Leopard, I had virtual hosts set up and running smoothly by following the instructions in the book. I just upgraded to Leopard a few days ago (using erase and install and then the Leopard installer migrated everything it could from the clone backup of my old Tiger system). Then I followed your new instructions online for “Enabling PHP and Apache in Leopard” and “Creating a virtual host in Mac OS X 10.5 (Leopard)”. I followed all of your instructions to the letter as far as I can tell.

    However, the first problem I’ve run into is that when I try to do the “note” after step 15 in the “Enabling PHP and Apache..” article, where you enter the two lines in terminal –
    cd /private/etc/httpd/users
    ls
    – I get the response back from terminal that no such directory exists. In fact, when I looked at my tree structure in TextWrangler, there is not even an httpd folder inside the etc folder.

    After trying to figure this out for a while, I went back to my clone of my Tiger drive and opened the username.conf file in the private/etc/httpd/users location and compared it to the username.conf file in the private/etc/Apache2/users location on my Leopard system and the files were already exactly the same. Here’s what they look like when opened:

    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all

    So I’m not sure what to do about that problem.

    My second problem is that when I try to access any of my virtual hosts, Safari can’t load the web page and I get this response – “Safari can’t open the page “http://egdwcs3/” because it can’t find the server “egdwcs3”. I get this same type of error with all of my virtual hosts.

    Any assistance would be greatly appreciated. Thanks!

    Edward

  6. Edward says:

    Oops – it looks like the web form edited my code for what the username.conf file looks like that was the same on both systems. I’ll try to write it again below without using carats:

    LEFTCARATDirectory “/Users/admin/Sites/”RIGHTCARAT
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    LEFTCARAT/DirectoryRIGHTCARAT

  7. David Powers says:

    Edward, the note after step 15 refers to an ordinary upgrade. Since you did erase and install, you won’t have the httpd folder. You can ignore that. The username.conf file looks fine – mine is exactly the same.

    Not sure why you’re not getting the virtual host recognized. If you followed the instructions, it should work.

  8. Edward says:

    Dear David,

    Thanks for your quick response to my posting. I went through all the steps on both articles you posted again just to make sure. I still can’t access the virtual hosts. However, when I tried to access the test.php page on the web this time, I got this message – “Safari can’t open the page “http://localhost/test.php” because it can’t find the server “localhost”.” Just wondering if this gives any clues as to what might be wrong.

    If not, is there any way to get back to the defaults that are installed with Leopard in case I’ve messed something up with PHP? (By the way, my Apache page that is linked to from the web sharing system preference still loads fine.)

    Thanks!

    Edward

  9. David Powers says:

    If it can’t find “localhost”, you have probably made a mess of the hosts file. Also make sure that you haven’t accidentally deleted NameVirtualHost *:80 in httpd-vhosts.conf.

  10. Edward says:

    Dear David,

    Thanks for your reply! I checked the httpd-vhosts.conf file and the NameVirtualHost *:80 line is still there. Below is what my hosts file looks like. Anything I should change? And if not, any other thoughts on what might be wrong?

    Many thanks,
    Edward

    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting. Do not change this entry.
    ##
    127.0.0.1 localhost
    255.255.255.255 broadcasthost
    ::1 localhost
    fe80::1%lo0 localhost
    127.0.0.1 trsvirtual
    127.0.0.1 tekvirtual
    127.0.0.1 rjvirtual
    127.0.0.1 remvirtual
    127.0.0.1 dwcsvirtual
    127.0.0.1 testvirtual
    127.0.0.1 lrcvirtual
    127.0.0.1 cmvirtual

  11. Edward says:

    I never could get it working after much research and headache. What I ended up doing was installing MAMP (and changing to the default apache and mysql ports in prefs per your suggestion on another site) and then using Headdress to set up the virtual hosts. The final missing link was to choose the folders for local root folder, images folder and testing server folder in manage sites the way you explained it in the book (select the exact root folder), but because Headdress uses port-based virtual hosts, the URL prefix field on the testing server pane of manage sites needs to say the address for the virtual site given by Headdress (i.e. http://localhost:9000/). After that, virrtual hosts finally worked again!

  12. Micah says:

    Hi, David. I’ve followed the instructions in your book and on this page for setting up virtual hosts and after hours of trying, I am having no luck. I get the Apache page when I go to http://localhost, but when I go to http://localhost/test.php, it says that the page can’t be displayed because it can’t find the server localhost. Also, it can’t find my virtual host. For example, going to http://choochoos gives me the error that it can’t find the server choochoos. Here’s how I set up the virtual hosts:

       DocumentRoot “/Library/WebServer/Documents”
       ServerName localhost

       DocumentRoot “/Users/micahovadia/Sites/choochoos”
       ServerName choochoos

    also, I did not delete the line “NameVirtualHost *:80
    ” from the file. Please help.

    Thanks!
    Micah

  13. John says:

    Hi, these instructions worked great and I can access the virtualhost locally (from the hosting computer) but when I try to access http://virtualhost from another computer on my network it still ends up going to the /Library/WebServer/Documents content. I have a DNS entry so that “virtualhost” points to the server IP, is there anything I’m missing to get this to work so other networked computers can use the virtual host?

    Thanks!
    John

  14. John says:

    Micah —

    You’re kind of having the same issue I am. You would need a DNS entry so that choochoos points to the IP of your server.

  15. Stuart Payne says:

    Regards problems with localhost we found today that Listen command in httpd.conf was in fact binding to IPv6 addresses when used in its default form Listen *:80. Its a fair bet like us that your machine is not actually using IPv6 so set it to Listen 0.0.0.0:80 and there you go.