Leopard, lookupd and local web development sites

As a web developer, I love the fact that my work machine can run apache, mysql and php. It makes my working life so much easier than all that ftp'ing then testing. It becomes even more important when you are working with Subversion; I think it good practice to work on a particular bit of a project until it is basically working, before those changes are committed. So my set up is that my SVN working copies become my apache docroots.

So, I usually have Apache 2 set up (along with MySQL, and PHP), via MacPorts, and using 'dynamically configured mass virtual hosting'.

This basically means that any calls to my local apache server will look in my sites folder for a directory with the same name as the requested domain name. In order to get the domains working under Mac OS X Tiger, I would just edit /etc/hosts pointing each domain to 127.0.0.1, then restart lookupd, and the whole system would work.

Great … except when Apple developed Leopard, they removed lookupd and thus, my means of pointing my local domains to my local server. Read on for the answer …

Technorati Tags:
developing, how to, Mac, osx, software, tips, tutorials, leopard

After a bit of searching, I found an answer; dnsmasq. Here is a quick run down of what I did to get it working under Leopard. NB: This is pretty MacPorts centric because that's how I did it, and thus assumes you are doing the same! This also requires a bit of terminal work.

  1. Install dnsmasq

sudo port install dnsmasq

  1. Create a copy of the sample dnsmasq config

sudo cp /opt/local/etc/dnsmasq.conf.sample /opt/local/etc/dnsmasq.conf

  1. Edit the conf file:

Find line 58 (#address=/doubleclick.net/127.0.0.1):
I added the following at line 59:

address=/.localsites/127.0.0.1

This points anything.localsites to 127.0.0.1 (obviously change this to whatever you want)

Then I enabled the ‘no-hosts’ directive at line 92:
Change:

#no-hosts

to:

no-hosts

  1. Now we need to make dnsmasq run all the time and in the backgorund. I used a launchd script:

sudo nano /Library/LaunchDaemonscom.steamshift.dnsmasq

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.steamshift.dnsmasq</string>
        <key>ProgramArguments</key>
        <array>
                <string>/opt/local/sbin/dnsmasq</string>
                <string>-d</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>

and save.

  1. Now run that file:

sudo launchctl load /Library/LaunchDaemons/com.steamshift.dnsmasq.plist

  1. Finally, in System Preferences > Network > Advanced… > DNS add 127.0.0.1 to the list of DNS servers.

Hopefully, if I haven't left out any steps, you should now be able to visit (for example, as set up above): mysite.localsites and be directed to your local apache server.

Please comment with your experiences with this!

SteamSHIFT out.

Update

After posting this, I received a helpful email from ‘Damian Bourne’ who pointed out the following:

Just read your blog entry on lookupd and dnsmasq.

I'm NOT saying anything bad about dnsmasq.. I use it lots of places.

I just wanted to let you know that lookupd was replaced with dscacheutil (as far as the command line is concerned), and that /etc/hosts still works.

I found that I didn't even need to flush the dns cache anymore for this to work, even when flip-flopping things around.

All the best,

Damian

Cool - another way, always useful. I think I will continue to use DNSMasq because of the wild card stuff, however, I have found one minor annoyance … which may force me back to /etc/hosts - if you don‘t have an internet connection, you can’t seem to point to a DNS server; Also when I am logged in via VPN to my uni network, I can't add my DNS server to the VPN network access. Hmm - any thoughts - please leave comments!

Copyright © 2013 - Brothers Bennettw - Powered by Hexo
- Ported theme GreyShade -