Google Search

Custom Search

Friday, December 11, 2009

Use Dynamic DNS to host websites from home

This article is primarily aimed at people who need to make their local development environment visible to the Internet. If you are interested in developing Facebook applications your ears should be perking up at this point. If you are interested in hosting your own website from home, there are more things to be considered than are covered here, so you should make sure and read some of the more authoritative articles on the topic.

The Facebook dilemma

Most Drupal developers use local copies of Apache, MySQL and PHP to develop their sites on their desktop or laptop machines. They then upload Drupal files and database dumps to a hosted web server when it is time for the site to go live. The model of working on a local site is great and saves a lot of development time because you can use good tools like Komodo, and you don't get bogged down by network lag.

Testing webservices is usually not a problem for the local installation because the vast majority of all Drupal sites are web service consumers. They access APIs from Amazon, Google, EBay, PayPal, Digg and Twitter using any number of HTTP based protocols. In almost every case the Drupal site instigates the web service transaction. Your local website knows how to find Amazon's services, so initiating the exchange isn't a problem.

This last detail is important because it is exactly where things change with Facebook. Facebook and its newly released API represents a new generation of web services in that Facebook is as much a web service consumer as it is a provider. Whereas Amazon's services sit and wait politely for your site to interface with them, Facebook is usually the initiator of any interaction between Facebook and your Drupal site.

Because your Drupal site must be available to Facebook during the entire development cycle of a Facebook application, your localhost environment will be inadequate unless you take some extra steps. The extra steps in this case are to use a service called Dynamic DNS to map a host name to your local development environment, and that is what I'm now going to show how to do.

The rest of this article assumes that you have a local instance of Apache (or some other web server) running on localhost:80. See this Lullabot article for instructions on setting up your local Drupal development environment if this is not the case.

What is Dynamic DNS and how do I get some?

Dynamic DNS is a service that keeps track of the IP address of your local machine and routes traffic for a particular host name to that IP address. This is useful when your internet service provider (ISP) assigns you a new IP address every time you make an Internet connection.

Normally, you map a domain, example.com, to an IP address like 140.211.166.6. This mapping then gets disseminated around the Internet and cached in a myriad DNS servers. The caching and disseminating is great when the mapping stays the same for a long time because it makes lookups fast and distributed. This feature of the system makes changing the mapping a lengthy process because that distributed cache needs to get updated. This can take 20 minutes to two days... not exactly the agility that you'd need if your IP changes once a day or more.

Dynamic DNS services consist of two parts. First, they provide normal DNS service for the host name in question. The difference is that the maximum caching time is set to a very low interval, such as 60 seconds. This prevents the DNS information from being cached in any other DNS servers and forces every lookup to be answered by the primary DNS server itself.

Second, the machine with the variable IP address needs a mechanism for telling the Dynamic DNS service provider what its current IP address is. This is done either by configuring your router to provide the service or by installing a software client on your computer to ping the DNS provider any time your IP changes.

Thus the first step in getting a Dynamic DNS hostname set up is to find a service provider. I chose DynDNS and will use them for the rest of demonstration. There are many other services available, however.

Setting up a DynDNS account

Getting an acount from DynDNS.com is easy. Make sure to remember your password (or if you generate it like I do, write it down), because you will need it later when configuring the router or the software updater. Once you've logged in to DynDNS.com using your new credentials, click New DynDNS Host to pick your hostname. While it is possible to register a domain and have that be managed by DynDNS, I found it more convenient to use one of the hostnames that they make available to you. After all, this is just to simplify my development process, not to host a real website from my laptop. Figure I shows how I configured the host. The IP address turns out to be irrelevant on this form because it is the task of the router or updater to keep DynDNS informed of this number.

No comments:

Post a Comment