How to access localhost from anywhere using any device.
How to Access Localhost from Anywhere
How many times, you have been working on an application (or an app) and you have designed and completed your application nicely. You have set up everything very nicely on your local system. Now you want to show this work to your client, who is sitting on a remote location. Also, you want to test this application on a different device ( such as mobile, tablets etc). To do these things, either you have to host your application on a public server, or you can use any service which allows to access localhost from anywhere.
To make this task easy and smooth, I am going to discuss one popular service called ngrok.
What is ngrok
ngrok provides a service through which you can securely expose a local web server to the internet and capture all traffic for detailed inspection and replay. It means ngrok provides a publicly accessible URL.
Using the publicly accessible URL given by ngrok, you can expose your localhost to anyone. Internally, ngrok creates a tunnel to a port on your local machine.
The Advantage of using ngrok services is that you can focus on development without any deployment.
How to Setup ngrok
1. Go to a download page. I am using Ubuntu. So, I have downloaded Linux 64 bit version. You can download as per your operating system.
2. Unzip the downloaded folder. Unzip using a terminal command.
1 |
unzip path_to_ngrok_folder |
In my case, my downloaded folder is in /var/www directory.
1 |
unzip /var/www/ngrok.zip |
3. I am running my PHP application on port 8000. My current localhost URL is http://localhost:8000 . To access my localhost for anywhere, I have to point the same port on ngrok as well.
Start with PHP built-in webserver
1 |
./ngrok 8000 |
Once your command is successfully executed, you get the following output.
1 2 3 4 5 6 7 |
Tunnel Status online Version 1.7/1.6 Forwarding http://4211e1da.ngrok.com -> 127.0.0.1:8000 Forwarding https://4211e1da.ngrok.com -> 127.0.0.1:8000 Web Interface 127.0.0.1:4040 # Conn 2 Avg Conn Time 50.53ms |
using this URL http://4211e1da.ngrok.com. I can access my localhost from anywhere. When you run ngrok in your system, you get different forwarding URL.
You can inspect traffic, through this URL 127.0.0.1:4040. It opens a dashboard, where you see inbound requests.
Apart from that, ngrok provides signup and paid features which includes,
1. Custom Subdomains
2. TCP Tunneling
3. Password Protection
4. Multiple Simultaneous Tunnels
5. Tunnel your own domains
6. Reserved Subdomains