Development with Mobile devices/VMs and local hosting

I’ve longed for a way to avoid having duplicate host files on all my virtual machines for a while now. And when I relalised there was is no way on iPad to modify hosts, I had to find a way. Here’s my solution, using a proxy on my host machine, and pointing iPad, mobile, and Virtual Box guest OSes to the proxy.

If you care at all about developing good websites, then you test on platforms other then the one you chose. These days, this includes mobile and tablet devices. I’m lucky with my latest projects, the target browsers are FF6+, Google Chrome, Safari 5 and iPad iOS5.

I usually host sites I’m developing locally, a simple LAMP setup. I then add a pseudo-domain to my hosts file /etc/hosts along these lines:

This is all well and good when I’m accessing the server from my own machine (which relies on this host file before DNS servers), but when inside a VM (Virtual Machine, I use VirtualBox running Win XP/7 and Ubuntu) testing, you have to mess about doing the same hacks to the windows/linux hosts file, and working out what the IP of the host OS is. I got sick of doing this.

And to top this off, when I got an iPad for testing, upon realising there is no hosts file, had to find another solution. This is where a local proxy server comes in. I’ve used Charles: Web Debugging Proxy for years. It’s perfect for inspecting requests and responses, can handles many types of data, AMF, JSON etc. Basically, it makes web application development a hell of a lot easier!

I then googled a bit, and found that if I set an HTTP proxy on the iPad, it would route DNS requests through there too. So the hosts file on my development machine, would work on the iPad!!! Simply start up Charles, then go to your WiFi settings on the iPad and configure the HTTP proxy. By default, Charles uses the port 8888.

You can also add these settings in any Virtual Machines you’re running on your machine. I’ve tested this in Windows XP and Windows 7 running on Virtual Box. If anyone tests this on Parallels, please let me know if it works.

Here’s some example configs on iPad and Windows 7 running in Virtual Box.

Comments are closed.