Posts Tagged ‘virtual hosts’

  1. Leopard Multiple Virtual Hosts

    When designing a new theme for this blog I discovered that the virtual hosts I had set up didn’t actually work (only having one)1. For these to work you need to use the IP address rather than an *.

    This means that a definition for a host needs to look like:

    /private/etc/apache2/extra/httpd-vhosts.conf
    <NameVirtualHost 127.0.0.1:80>
     
      DocumentRoot "/Library/WebServer/Documents"
      ServerName localhost
     
      DocumentRoot "/Users/user/Sites/site"
      ServerName blog.dev
      ServerAlias www.blog.dev
     
        Options FollowSymLinks
        AllowOverride All

    The biggest change is in that I added another definition (to ensure that the standard webserver still worked), as well as adding the local IP and port (127.0.0.1:80) to the definition. This is due to the way in which Apache 2 processes definitions, and was actually broken in the first version I put together.

    As an addendum if you type apachectl configtest into the terminal it will tell you if there are any errors in your .conf files.
    1. see this post for what I did originally, as most of that is still relevant
  2. Apache Virtual Hosts on Leopard

    Setting things up:

    Firstly, in /etc/apach2/httpd.conf comment out the line

    # Include /private/etc/apache2/extra/httpd-vhosts.conf

    This will allow you to use the virtual hosts file buried in /private/etc/apache2/extra/httpd-vhosts.conf

    Open up the file httpd-vhosts.conf1, and comment out all of the examples (use #), leaving only NameVirtualHost *:80 uncommented.

    Next, add your virtual host:

    <virtualhost *>
      DocumentRoot "/Users/your_user/Sites/your_site"
      ServerName your_site.dev
      ServerAlias www.your_site.dev
      <directory "/Users/your_user/Sites/your_site/">
        Options FollowSymLinks
        AllowOverride All
      </directory>
    </virtualhost>

    One you’ve done that you need to add the address to /etc/hosts. Simply add the line

    127.0.0.1   www.your_site.dev

    to the file.

    More information can be found on: http://www.givegoodweb.com/post/53/cakephp-leopard-virtual-hosts and http://www.456bereastreet.com/archive/200711/virtual_hosts_php_and_mysql_on_mac_os_x_105_leopard/
    1. remember it’s a system file so you’ll need to sudo it