When developing sites for mobile devices, I have often wanted a way to view my MAMP virtual hosts on my iPad or iPhone without having to upload the site to a live domain. In the past, I have used CNAME redirects to point specific domain names to my local computer, to help with this issue, but DNS propagation usually takes 24 hours and I usually need to develop my sites sooner than I can wait.
I recently moved to a new location and my ISP prevents this from working for local devices, based on the router they provided for me, so I set out to find a new way to make this happen.
From the website: SquidMan is a MacOS X graphical installer and manager for the Squid proxy cache. It is designed to operate as a “personal” proxy server.
When you run Squid on a MacOS X computer, it can:
- cache downloaded content, reducing network traffic and improving browsing performance on slow links
- act as a proxy server for other computers on your subnet
- restore the operation of some MacOS X applications that normally fail through authenticated proxy servers
The part I was most interested in was the proxy server. I figured that if I could create the host redirect on my local machine, and then use my iPhone and iPad to connect to it directly, I would be able to view my virtual hosts on my development machine, since all traffic would be routed through that location. I was right. Here are the steps I took to accomplish this:
1. Install and Configure SquidMan.
Installation of SquidMan is very easy and does include the Squid proxy server, so you don’t need to download it separately. The first screen to appear was the preferences pane. The default port is 8080 and this is what I left it at. You can change this to suit your needs.
The only other tab you need to alter is the Clients tab. You want to restrict the use of this proxy to members of your local subnet to prevent outside access to your proxy server. Just click on the clients tab and set up the options based on the instructions next to it. I set mine up to work for any computer connected to my local network.
Once you have finished that, save and then start your server.
2. Set up the Proxy on the iOS devices.
On my iPad and iPhone I then set up the new proxy server. I went to the Wi-Fi tab and then selected my local network. I then set the HTTP Proxy to “Manual”. In the server field I used the IP address of my local machine, and then I added the port from the SquidMan settings.
From this point if you can browse the web, you have successfully connected your device to the proxy. For my installation however, there was still one more step I needed to do to finish this setup.
3. Add IP address to virtual host inside MAMP.
When trying to access my virtual hosts via the hostname set up inside MAMP, I would receive an access denied error message.
I found an easy fix to this by visiting my MAMP settings and adding the IP address of my localhost in the IP/Port settings of the virtual host. For some reason, MAMP does not seem to like IP Addresses that have 0’s in them. If your subnet range is like mine, you will see the red exclamation mark next to the IP address. You will also not be able to type in the address directly, but will need to select it from the drop down list. You can then apply your settings and restart the SquidMan server for it to take effect. NOTE: If you are unable to apply your settings, visit the MAMP preferences and select the option to allow apply when the IP of a host isn’t valid.
After saving and restarting both MAMP and SquidMan, I was able to view my virtual host on the iPad.