Accessing Localhost From Anywhere
Accessing Localhost From Anywhere
Programming
July 1, 2021
Share:
You’ve spent hours working locally on your computer, getting that new website
design to look just right. Your CMS is nicely set up with sample content and you
want to test it out on a few mobile devices and tablets. Your client also wants to
take a look — but you don’t have time to migrate it all to a public server to give
them a quick peek.
If you’re a web developer, chances are you’ve been in this situation plenty of times.
And you probably spent those times burning a little midnight oil migrating things
onto a public-facing server wishing there was an easier way.
To all those tired-eyed web developers out there, I’m here to tell you that an easier
way has arrived! In fact, a whole slew of applications and services are available to
help make this process easier by providing access to your localhost from the Web.
The ones I’ll be discussing in this article are:
ngrok
FREE JavaScript Book
PageKite
Valued at $11.95 on Amazon. Yours free!
localtunnel
Name boringproxy
[email protected] Submit
BrowserStack
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 1/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
It’s possible through secure tunnel services online! These are services that provide
you with a tunnel from the Internet to your machine.
What that means is that they provide a publicly accessible URL, watch for calls on
that URL, and forward those calls to your localhost server. All the confusing setup
has been done for you; all you need to do is install an application and point it to your
localhost.
On my localhost, I’ve got virtual hosts set up. Without having the address from each
service below listed as a ServerAlias , my server would refuse to play nicely. A
few hours of confusion ensued. If you’re in the same boat, add a ServerAlias to
your httpd.conf , replacing the ngrok address you see below with the address
from the service you’re using:
<VirtualHost *:80>
DocumentRoot "/Users/patcat/Web"
ServerName mytestsite.test
ServerAlias 350c0f8e.ngrok.com
</VirtualHost>
Namengrok is an [email protected]
application for Windows,
Submit macOS and Linux that creates a tunnel but also
allows you to inspect all traffic that goes through the tunnel and replay that traffic for
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 2/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
testing.
You can use basic features for free and then sign up to access more advanced
features. In order to use custom subdomains and reserved domains, you’ll need to
sign up for a paid plan. Otherwise, you’ll be able to use the service, but will be given a
random domain such as the 350c0f8e.ngrok.com URL in the virtual host
sample above.
One key advantage to ngrok is that it has no dependencies. You install ngrok and run
it. Nothing else is required.
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 3/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
Open up a command-line terminal and go to the folder you extracted ngrok to. Run
the following command to create a tunnel to your localhost on port 80:
./ngrok http 80
In the example above, we’ve got traffic to a randomly generated ngrok address of
http://42e474ef9799.ngrok.com being forwarded to our localhost on 127.0.0.1:80.
Open that URL on any device with an internet connection and you’ll be accessing
your localhost from the Web!
One of the more unique offerings ngrok provides is the ability to inspect past traffic.
To do that, go to http://localhost:4040/ on your computer. You’ll access a dashboard
showing inbound requests. You can click each request on the left and see details on
the right for the headers and other data. My favorite use of this is seeing JSON data
returned back from requests. The very basic layout of this when loading a simple
FREE JavaScript
HTML Booklike this:
page looks
Valued at $11.95 on Amazon. Yours free!
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 4/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
You can even replay a request by clicking the Replay button on the right. That will re-
run a request for you over the tunnel.
Custom subdomains are for when you don’t want to have to remember that
randomly generated URL! If you sign up to a paid ngrok plan, you can reserve a
subdomain so others can’t take it. The following allows you to view your localhost at
nogophersinmytunnel.ngrok.com:
FREE JavaScript Book
Valued ngrok
at $11.95 on Amazon.
http Yoursnogophersinmytunnel
-subdomain free! 80
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 5/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
Custom domains are for when you’d prefer to not have “ngrok” in your URL for the
tunneled project. Paid plans allow you to use your own domains, rather than needing
to use ngrok.com:
You can even tunnel to an IP address on your local network that otherwise would not
be accessible to the outside world:
ngrok tcp 22
There are a bunch of other things you can do, from running multiple tunnels at once
to creating a config file to save all these settings for future use.
PageKite
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 6/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
You can sign up for a free trial for a month and 2.5GB of transfer quota. After that it
has a pay-what-you-want system (a minimum of USD$4 a month, or free if you work
on free open-source software). You do need to pay more to get more in this case
though, with those paying larger amounts getting a larger quota, a longer term of
service, custom subdomains, and so forth.
PageKite doesn’t appear to have a traffic inspector like ngrok, but it does have rather
incredible features like a built-in firewall that blocks access to common attack
targets like /wp-admin , /xampp , phpMyAdmin pages … and so on. It can be
disabled if you’re okay with these being public.
They’ve even got a front-end relay server in Sydney, Australia, so this could
potentially provide faster speeds for Australian developers.
Once downloaded, run this command to run a tunnel to your localhost server. You
choose a specific subdomain which you use each time (rather than the random
allocation in ngrok). I’ve chosen hurrygetintothefancytunnel here:
pagekite.py 80 hurrygetintothefancytunnel.pagekite.me
FREE
OnJavaScript Book I needed to run with python3 at the start, so try that if the
my Mac recently,
above
Valued doesn’t
at $11.95 work: Yours free!
on Amazon.
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 7/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
It’ll run through and sign you up to the service if you’re not already signed up. Then
you’ll have localhost up and running for the world!
One example: there’s no need for a web server. If you don’t have a server running, it
has an inbuilt web server that can run your static files like this:
Valued pagekite.py
at $11.95 on Amazon. Yours free!
80 arcadefirecamethroughmywindow.pagekite.me +ip/1.2.3.4=ok +ip/4.5.6=o
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 8/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
As mentioned above, you can even run all of this on your phone. I installed an
Android web server called kWS and then ran PageKite to expose it to the Web:
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 9/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
It’s definitely not something I’ll be doing every day, but it’s pretty neat to see that this
stuff is now possible solely on a smartphone!
Just like ngrok, PageKite can do multiple tunnels at once, and it supports having your
own domain, and supports setting up a configuration file for your tunnels. For more
on this, check out their Quick start guide and their more comprehensive how-to
page.
localtunnel
localtunnel is a tunneling service that was initially built in Node but also has Go-
based and C#/.NET clients.
In order to start a tunnel to your localhost on port 80, you run this command:
lt --port 80
It’ll run just like ngrok and PageKite! It gives you a subdomain something like the one
I was given: https://loud-ladybug-21.loca.lt .
FREE JavaScript Book
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 10/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
When first running localtunnel, you’ll receive a friendly reminder that this action is
making your assets public to the Web. Just hit Click to Continue.
One
Valued of theon
at $11.95 very handy
Amazon. features
Yours free! localtunnel provides is a Node API that allows you to
Name
generate localtunnels
[email protected]
via JavaScript
Submit
to use in your automated tests:
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 11/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
(async () => {
tunnel.on('close', () => {
});
})();
boringproxy
boringproxy is a newer option that’s totally free and open source under the MIT
license! Its main focus appears to be making it easier for people to self host
websites on their computers. It comes as a single executable file that works as the
server and the client in one. There’s an executable for a range of Linux systems and
Windows. macOS is listed as “untested”. I haven’t been able to get it to work on my
Mac personally, but if you have access to a Linux box or a Raspberry Pi, this just
might be the solution for you. It’s all written in Go and is open for contributors.
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 12/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
The main steps are easiest followed on the boringproxy documentation, as it’s
different for different platforms.
Overall, it involves:
downloading the server instance via curl (for example, curl -LO
https://github.com/boringproxy/boringproxy/releases/download
linux-x86_64 )
chmod ing the executable that was downloaded (for example, chmod +x
boringproxy-linux-x86_64 )
setting up binding to ports 80 and 443 (for example, sudo setcap
cap_net_bind_service=+ep boringproxy-linux-x86_64 )
setting up the executable on the client too
This video from the creator of boringproxy covers the how-to best:
boringproxy demo
Name
Advanced features ofSubmit
[email protected]
boringproxy
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 13/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
Auto HTTPS certificates are automatically managed for you via Let’s Encrypt. No
need to stress about getting certificates for testing, as it happens behind the scenes.
You can tunnel web applications with ease. Self host web apps like Etherpad
(shown in the video above), give them their own subdomain, and then you can
access them from anywhere.
BrowserStack
You can use the above methods to test localhost sites in the BrowserStack virtual
machines, but it also has a browser extension for Chrome and Firefox allowing you
to provide access to your localhost from their servers.
However, this functionality is only for the BrowserStack services and isn’t accessible
to the general public. BrowserStack comes with a free trial, after which it will cost
you a monthly fee to use the service. It’d be handy for cases where the sole reason
you’re looking to access localhost is to do device testing.
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 14/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
In the end, though, it’ll allow you to test your localhost sites in virtual machines run
over the Web like so:
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 15/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
After playing around with all of these options, my personal favorites would have to
be ngrok and PageKite.
PageKite seems like the most multifaceted solution with a huge amount of potential.
It’s been developed and extended to fit a range of uses over the years, making it a
really impressive application!
ngrok is great too for its simplicity and the traffic inspector. It has more than enough
features for most web developers looking to access their localhost from the Web.
Conclusion
If you’re working on a computer with an active internet connection, you can now set
up access to your localhost from anywhere in only a few minutes! It’s incredibly
simple to get started and, as you’ve seen, there’s no shortage of solutions!
Have you used any of these services? Do you have any others you prefer? I’d love to
know your thoughts on Twitter!
Tags
browserstack device testing localhost localhost tunnel ngrok pagekite proxylocal
testing localhost
Patrick Catanzariti
PatCat
Valued is the founder
at $11.95 of Dev
on Amazon. Diner,free!
Yours a site that explores developing for emerging tech such as virtual and
augmented reality, the Internet of Things, artificial intelligence and wearables. He is a SitePoint contributing editor
for emerging tech, an instructor at SitePoint
Submit
Premium and O'Reilly, a Meta Pioneer and freelance developer who
Name [email protected]
loves every opportunity to tinker with something new in a tech demo.
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 16/17
7/5/2021 Accessing localhost from Anywhere - SitePoint
Advertise
Connect
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
https://www.sitepoint.com/accessing-localhost-from-anywhere/ 17/17