Testing your local websites on smartphones using a Squid proxy server.

This is a guide to install and configure your own Squid proxy server, for testing and debugging local websites, using your local hosts file to route the requests.

I have a local development environment configured with many VirtualHosts running on my local Apache webserver. I map local domain names to localhost (127.0.0.1) in my local hosts-file but that only makes these domains available on my local machine. Using the Squid proxy you can make local domains available for all your external devices.

This guide does not consider security whatsoever. Read the details
of squid.conf to setup your own security after you have installed Squid.

Mac OS

Installation

I'm going to use Macports to install Squid, a free proxy server. If
you do not have Macports installed, go check it out – this guide will not work without it.

In terminal, type:

sudo port install squid

Add permissions to cache storage:

sudo chmod -R 777 /opt/local/var/squid

Update Squid configuration

Open the configuration file in your preferred editor:

/opt/local/etc/squid/squid.conf

In the configuration file, locate and uncomment this line:

hosts_file /etc/hosts

Create swap folders

Simply run Squid the first time using the -z parameter to let Squid create the required swap folders. In Terminal run:

squid -z

Run Squid

Start Squid in no daemon mode. This means it runs until you quit it by pressing ctrl-c.

squid -N

Start Squid, do your testing and quit the process when you are done. Thank me later :)

Yes, that's it.

Windows 10

Installation

Squid is available as a Windows .msi installer from squid-cache.org. Download the latest version and run the installer.

The installer will add a Squid Windows service to your computer and while this is convenient it is also a bit more than we need for just occasional testing. Consider to switch the service to manual, so it doesn't run in the background all the time.

Update Squid configuration

Open the configuration file in your preferred editor:

etc/squid/squid.conf

On Windows this file is located inside the etc folder in the Squid application folder. You can change the install location through the installer, so I don't know where it might be on your computer.

In the configuration file, locate and uncomment this line:

hosts_file C:/Windows/System32/drivers/etc/hosts

If you can't find that line in the configuration file, then just add it to the end of the file.

Restart Squid

Go to Services and restart (or start) the Squid service.

dffd

Setting up local domains via your hosts file

To make your local domains available on your test devices update the entries in your local hosts-file pointing them to your own computers local network IP, like:

192.168.1.42 parentnode.proxy

Unfortunately you might need to update this whenever running the proxy server on a new network, or if your IP changes. I use a dual configuration, with one entry for testing on my local machine and another entry for proxy based testing. Thus every local domain entry in my hosts file looks like:

127.0.0.1 parentnode.local
fe80::1%lo0 parentnode.local
::1 parentnode.local 192.168.1.42 parentnode.proxy

Make sure your local Apache is ready to respond to your new proxy domain as well. In the Apache configuration for your project, you can add an Alias for the proxy domain:

ServerName parentnode.local
ServerAlias parentnode.proxy

Note: You cannot access .local domains on iOS devices

Configure proxy on smartphones

iPad/iPhone

Go to Settings on your iOS device. Choose WiFi, and click the i-icon on your network to edit network configuration. Choose Configure Proxy. Choose Manual and enter the IP-address of your local computer and port number for Squid (3128).

Remember to start Squid on your computer.

Android

Go to Settings on your Android device and choose Wifi. Touch and hold on the active network and choose Modify Network from the menu that shows up.

Choose Advanced options and then select Manual from the proxy options and enter the IP of your local computer and port number for Squid (3128).