Saturday, 22 March 2008

VirtualHosts in Apache, Leopard

There's a few key files when playing with Apache WebServer. They are all .conf files, the most important being http.conf. In Leopard this is at etc/apache2/. Editing this file is pretty straight forward, it's very templatey - find out where it's done once, then copy, paste and edit.

Virtual hosts are a good thing to set up if you're working with a lot of websites. People talking about enabling the following line beginning with Include in the http.conf file:

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

This is fine, but it doesn't really do anything, it just gets Apache to pull in that extra configuration file when starting up. In fact, you can keep that file commented out (not used) and put virtual directory right there, in the http.conf file. Here's the basic code for setting up a virtual host

<VirtualHost *:80>
#ZDS Name: redmonkey
ServerName redmonkey
DocumentRoot "/Users/michele/Sites/redmonkey"
ServerAlias redmonkey
ErrorLog error.log
Options Indexes MultiViews Includes

I'm sure loads can be changed, and I'm not sure what all of it does yet, but get this in and edit the rest.

Once this is done, you need to setup your hosts file. This can be found in /etc/ and it's simply called hosts (note: no file extension). Here add the following: redmonkey

The IP address is equivalent to "localhost" and then a name of your new hosts. From then on you should be good to go with your new hosting directory in Apache on Leopard.

No comments: