22 Oct 2008

More Apache Hassles


I want to include the vertical menus on my webside by server side includes -

using the <!-- #include --> directive - this however took me a little while to cope with.

Firstly there are two forms -


<!--#include file="somefile.html" -->
<!--#include virtual="someotherfile.html"-->


now file will strangely not resolve any file that isn't in or below the directory of the file that
it is currently being included from. i.e. fully enumerated paths and the '..' symbol won't work.

virtual on the other hand will include a file anywhere, but importantly starts at the 'document root directory'

In apache2 as included and installed in mac OSX 10.5.5 the document root is /Library/WebServer/Documents

which is different from the individual users Site home directory. which is in a directory something like -

  
/Users/someuser/Sites


As I don't want to host my website from that directory - i have to go back and change the apache
config file again - which regular readers may recall is hidden away in private/etc/apache2/httpd.conf

it turns out you need to change this to -


#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Library/WebServer/Documents"
and replace with the path to your sites folder, mine is "/Users/someuser/Sites"


Then find-


#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/Library/WebServer/Documents">
And change there as well, e.g.

<Directory "/Users/someuser/Sites">


restarting apache2 is of course necessary to make it work....

\\localhost should change - but \\localhost wont find an index.shtml which is annoying.


click here to return to the blog