Wednesday, July 20, 2005

Accessing LAN websites under OSX (Panther) served by Apache on Windows

Like most web developers, I test my sites on a web server running locally on my machine - at the moment that's Apache 2.048 under Windows XP.
I set up virtual servers for Apache so I can develop relative to a domain root.
For a couple of years I've lived with a problem when testing a site from another machine on the LAN - for example my MacMini (OSX - Panther): While I see a site under 'http://mysite" on my PC , on the MiniMac I have to enter something like "" - this is not only annoyingly longer, If I'm working with absolute paths, I have to reconfigure the site in order to test it.
The solution is not too difficult, but I couldn't find a straightforward example, so here is my working setup . (Note. This is an example rather than an explanation. It isn't for newbies. If you don't know what httpd.conf is, then this example probably isn't for you):

1. The Apache Virtual Server configuration. Here is the relevant section of my httpd.conf. Note the use of '*' after NameVirtualHost and VirtualHost.

NameVirtualHost *
<VirtualHost *>
    ServerAdmin admin@localhost
    DocumentRoot "E:\WWW\path_to\mysite"
    ServerName mysite
    ServerAlias *.mysite
    ErrorLog logs/mysite.log
    <Directory "E:\WWW\path_to\mysite">
        Options All Includes Indexes

2. And here the hosts file on XP (something like C:\WINDOWS\system32\drivers\etc\hosts)

... a_site mysite another_site
3. So now you've got get http://mysite working locally (Once you've restarted apache of course). Next you need to set up the Mac. I use NetInfo to edit the OS X equivalent of the hosts file. Here's what my setup looks like:

so you create an entry under machines. give it the ip_address of the server (in this case the PC running Apache), and the name of the site.

Now http://mysite works on the MiniMac too! This saved me a lot of hassle.


Post a Comment

<< Home