0

I am running Apache on my Mac OS X (Snow Leopard) machine. I want to be able to set up multiple hostnames so that I can develop and test multiple sites at the same time, but I can't seem to get this to work.

Here's what I've tried:

In my etc/hosts file I've set added these entries:

127.0.0.1    testsite1.localdev.com
127.0.0.1    testsite2.localdev.com

Then, in apache2/httpd.conf I have added these entries:

<VirtualHost *:80>
   DocumentRoot /Library/WebServer/Documents/www/development/testsite1
   ServerName testsite1.localdev.com
   <Directory "/Library/WebServer/Documents/www/development/testsite1">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot /Library/WebServer/Documents/www/development/testsite2
   ServerName testsite2.localdev.com
   <Directory "/Library/WebServer/Documents/www/development/testsite2">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

But happens is that both hostnames resolve to the first one listed in the httpd.conf file -- in this case, testsite1. If I switch their positions, then they both resolve to testsite2.

I've also tried changing the area that reads *:80 and replacing that with the specific hostnames for each site, but that has no effect.

I am being sure to reboot apache after each change.

Thanks for any help!

Gary

Gary
  • 453
  • 4
  • 15
  • FYI everyone: I found the answer I needed here: http://stackoverflow.com/questions/683891/how-to-fix-this-virtual-host-setup – Gary Mar 16 '11 at 00:17

1 Answers1

1
  • in /etc/apache2/httpd.conf uncomment the vhost file like:

    # Virtual hosts
    Include /private/etc/apache2/extra/httpd-vhosts.conf
    
  • in /private/etc/apache2/extra/httpd-vhosts.conf use...

    #
    # Use name-based virtual hosting.
    #
    NameVirtualHost *:80
    
    <VirtualHost *:80>
        DocumentRoot "/Library/WebServer/Documents"
        ServerName localhost
    </VirtualHost>
    
    # local test site
    <VirtualHost *:80> 
      <Directory /Users/<youruser>/Sites/test>
        AllowOverride All 
      </Directory> 
      DocumentRoot "/Users/<youruser>/Sites/test"
      ServerName test.local
    </VirtualHost>
    
  • Be sure that your and Sites folders have permissions of 755

and be sure that you add to your /etc/hosts file...

# test
127.0.0.1   test.local
pixelhandler
  • 615
  • 4
  • 11