Lion takes long to connect to local server

Does your /etc/hosts file look like this?

[code lang=”bash”]127.0.0.1 gladlycode.local gladlycast.local
127.0.0.1 babyessentials.local kw.sg.local
127.0.0.1 localhost[/code]

Every request I made to gladlyCode.local takes 5 seconds to resolve to my local Apache server. Something was wrong!

If it does and you’re on Mac OS X Lion, you should change your VirtualHost names to something else. It turns out that Mac OS X Lion no longer looks up /etc/hosts first when you try to lookup a .local domain since are technically reserved for Multicast DNS (MDNS), or Bonjour. Starting Lion, it will lookup through MDNS first, and after the 5 second timeout, it checks with /etc/hosts.

This is at a cost of developer productivity and I have to change all my .local domains to .internal.kw.sg which is a domain name I own. I figured that if it is a domain name I own, it will never clash unknowingly. I changed ‘gladlycode.local’ into ‘gladlycode.internal.kw.sg’ and point it to 127.0.0.1 now. Now testing gladlyCode no longer takes 5 seconds per request (ridiculous!).

Alternatively you can use another top level domain (TLD) instead of .local and the common ones such as .com.

How to set up VirtualHost in Ubuntu

My environment is Ubuntu 8.1 Intrepid Ibex. I also written a guide on how to set up virtual hosts in Windows XP or Windows Vista.

0. Introduction

Sometimes, we have multiple projects and we would like to access the Project 1’s website by typing ‘http://project1/’ in the browser address bar. And Project 2 may be at ‘http://project2/’. Virtual hosts are what you need for your development work. This guide requires you to have basic knowledge of Apache. This guide assumes you haven’t done additional configuration to your Apache. You must have already got Apache2 installed.

Also remember that you should always do a backup of every configuration file you change.

1. Add a new host in Ubuntu

You should only be adding new hosts if you want to develop multiples sites in your local computer. Skip this section to go to Section 2 if you just want to add virtual hosts to a remote server.

Type in the following command into your terminal, you need to sudo here: Continue reading “How to set up VirtualHost in Ubuntu”

How to set up VirtualHost in XAMPP for Windows

My environment is Windows Vista but these instructions work for Windows XP as well. I also written a guide on how to set up virtual hosts in Ubuntu.

0. Introduction

Sometimes, we have multiple projects and we would like to access the Project 1’s website by typing ‘http://project1/’ in the browser address bar. And Project 2 may be at ‘http://project2/’. This is how we can configure Windows and Apache to do just that. While this guide is written for XAMPP’s Apache, if the instruction applies pretty much to Apache too. You can put your configuration into ‘httpd.conf’.

1. Add a new host in Windows

First go to your hosts file, it is located at C:WindowsSystem32driversetchosts for most people. If you’re using Windows Vista, you need to run command prompt as administrator. Type ‘cmd’ into the search bar and right click on the ‘cmd’ search result to point to ‘Run as administrator’. Continue reading “How to set up VirtualHost in XAMPP for Windows”