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
2. Unzip the downloaded folder. Unzip using a terminal command.
In my case, my downloaded folder is in /var/www directory.
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.
Once your command is successfully executed, you get the following output.
Tunnel Status online
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
1. Custom Subdomains
2. TCP Tunneling
3. Password Protection
4. Multiple Simultaneous Tunnels
5. Tunnel your own domains
6. Reserved Subdomains