*

2008 / October 24th/ Super simple virtual hosts for the OSX inclined

When it comes to setting up virtual hosts on OSX, I’ve seen people go to no end of trouble to get them setup. Most people I know use a mix of 3-4 applications and manual editing of their /etc/hosts file. But why go through so much pain?

OS X Leopard comes with just about everything you need to get going on a local development environment. Apache is already installed and ready to go. Just add in your flavor of mods (mod_rails, mod_php, mod_python, etc) and you’ve got a nice local development environment setup. But for me, 90% of the time I want just a quick way to test out an HTML site — something Apache is just fine at. Instead of going overboard with apps like Headdress, MAMP, etc — I just whipped up a quick shell script.

Throw this puppy into somewhere like /usr/local/bin/vhostit and you can setup virtual hosts in no time flat (remember to use sudo when executing this command). Go to the directory with your html, type in vhostit sample.dev, then go to your browser and type in http://sample.dev and you’ll see your site. Nice and simple. No extra applications. Just Apache and some good old shell scripting.

Aside: if you’re looking for a painless rails environment I really cannot recommend Passenger PrefPane enough. Seriously — if you develop with rails and aren’t using this, you’re adding unnecessary pain into your workflow.

9 Comments

comments feed

  1. Gravatar
    Kyle

    October 24th | #

    Wow, great stuff! I’ll definitely be putting this to use.

  2. Gravatar
    Patrick

    October 25th | #

    Wow, thank you so much!

    I just recently wanted to set up some virtual hosts for some projects I’m working on and there was a small typo I made in the configuration file which resulted in a wrecked Apache. Fortunately I was able to fix the problem but it’s just a pain in the a** to set it up manually every time.

    Greetings

  3. Gravatar
    ben

    October 25th | #

    Hot damn! That’s pretty sweet!

  4. Gravatar
    Matthew Pennell

    October 27th | #

    Awesomeness! Just need to replace the apachectl line with the MAMP equivalent, and I’ll be using this all the time. :)

  5. Gravatar
    Guillermo Rauch

    October 28th | #

    Using it already :) I was going to make this for myself eventually!

  6. Gravatar
    Kash

    October 30th | #

    cool script, thanks.
    i did some modification to use it with MAMP.
    i’ve changed the following lines:

    from:
    HTTPDFILE=”/etc/apache2/httpd.conf”
    to:
    HTTPD
    FILE=”/Applications/MAMP/conf/apache/httpd.conf”

    from:
    $(apachectl restart)
    to:
    $(/Applications/MAMP/bin/apache2/bin/apachectl restart)

  7. Gravatar
    Thomas

    December 9th | #

    Might I at the tip of a hat recommend VirtualHostX (www.clickontyler.com).

    Very nice app, that does the same and whole bunch more.

  8. Gravatar
    Kyle

    December 9th | #

    … and costs money. Mine is free as in beer.

    I guess I just can’t consciously pay for something that I can replicate with a couple of lines of bash scripting.

  9. [...] for 2008-10-27 Super simple virtual hosts for the OSX inclined – Warpspire A shell script to set up virtual hosts on your Mac OS X machine for web development. Nice. (tags: [...]

Make a Comment

don’t be afraid, it’s just text

Comments are parsed with Markdown. Basic HTML is also allowed.