07 April 2012


EDIT (March 21, 2013): I've stopped using localtunnel due to its servers always being down. Luckily I've found a service called Pagekite (http://pagekite.net/) which does pretty much the same thing and with a lot more options.

The Problem

Imagine this: You're working on an important site or design for a client. It's Sunday morning and you're camped out in the back of a Starbucks, not because the coffee is good (it isn't), but because it has the most reliable internet and freakishly large sizes which let you deliver the maximum caffeine possible and stay the longest time.

Your design is done and the client IM's you. "Can I see it?" he says. Now you have a problem. You could spend 5 minutes setting up an SSH tunnel or trying to bypass the firewall of the Starbucks. You could upload it to some public server you own but that will take time and the client needs to see it now! Like a manic chicken you hit screen capture on every page and send the client links to the Dropbox.

There has to be a better way...

The Solution: LocalTunnel

LocalTunnel is a Ruby script that instantly exposes a single port on your local PC to a public URL temporarily. It's nothing new or groundbreaking but it's a great example of doing something quickly to save you time and your clients a headache.

Here's how it works. You run the command and give it a port number (a common one is 80 or 8888 for default MAMP) and then based on that it spits you back a URL like http://8bv2.localtunnel.com. The 8bv2 subdomain part is your unique identifier and it is different every single time you run localtunnel. Once you have this address anyone can.


For instructions on how to install and troubleshoot check out the LocalTunnel main page. Installation can be a one-command deal but it's not always. It was on my work iMac anyway. At home, on Lion for whatever reason it wouldn't work so I needed to dive into Ruby a little.

What worked in the end was to install Homebrew (http://mxcl.github.com/homebrew/) which lets you have really specific control over Ruby install versions etc.

Maintaining Control with Symlinks

I use MAMP to develop locally which has apache (M(Apache)MP) so getting up and running was as easy as tweaking the httpd.conf file a bit. I'm a little paranoid about exposed ports and sites so I like to set it up so that I have direct control over what people see.

It's pretty simple actually. All you need to do is make the folder that MAMP serves an empty folder with symlinks to where it lives. Then when you don't want to share that site anymore just sever the symlink. The following illustrates what I mean. I'm assuming you know how to set up your web server using httpd.conf or whatever equivalent.

/Sites/LIVE   # The folder you serve to the world at
/Sites/SiteA  # The folder you'd like to serve

$ cd /Sites/LIVE
$ ln -s ../SiteA  #Cool. Now we're serving SiteA at

When I'm ready to cut the cord:

$ unlink /Sites/LIVE/SiteA

Taking it a little further and making it pretty

If all you did was put sites into subfolders when you point clients to the root localtunnel address they'll get a blank screen or worse, a directory listing. Both of these are considered bad form and the latter is also a security problem.

I use a combination of PHP and the bootstrap framework to make  a nice autodetecting menu selector that looks like this:

There's nothing fancy here. I use a PHP command to automatically find all subdirectories and list them in a nice way. What this lets me do is to show entire sites as options to client. Choose door A, B, C etc. [gist id=2321579]

Some Security Considerations

There's the usual concerns about sharing a public key but overall I trust the folks at twilio so that's probably not an issue.

You're only exposing a single port and only ever temporarily. The second you quit localtunnel the link is severed. That being said the usual applies.

  • Don't use easy passwords for your MySQL databases or root accounts. If someone finds a way to execute PHP code on your system they could get root access.
  • Make sure your versions of PHPMyAdmin and other services are patched and up to date.
  • Use the symlink method above to expose only what you want people to see.

LocalTunnel by twilio

This is the first in a series of posts about workflow and a number of new tools I've found that are speeding up the way I work. Sorry to those who might not find this interesting.

EDIT (March 21, 2013): I've stopped using localtunnel due to its servers always being down. Luckily I've found a service called Pagekite (http://pagekite.net/) which does pretty much the same thing and with a lot more options.

Filed in: Nerd  

Comments: This is a tiny site and comment moderation is a pain. Let's use social links to have a conversation on a bigger platform: