paint-brush
Make Your Localhost Available Onlineby@mabakac
1,537 reads
1,537 reads

Make Your Localhost Available Online

by April 19th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Localtunnel allows you to easily share a web service on your local development machine without messing with DNS and firewall settings. It will assign you a publicly accessible publicly accessible URL that will proxy all requests to your locally running webserver. To develop skills locally, we can use a completely free method with Localunnel. You can also use a custom subdomain without having to pay for it.
featured image - Make Your Localhost Available Online
undefined HackerNoon profile picture

Intro

The most easily accessible and immediate environment you have access to is on your very own computer. With Localtunnel it is easy to share a web service on your local PC without having to mess with DNS and firewall settings. It will assign you a unique public url that will proxy all requests to your webserver.

Why Localtunnel?

You might ask why you want to use a Localtunnel. For example, Amazon needs a request onto your web server and you can’t just use your localhost. It needs a website origin and allowed return URLs. An origin is the combination of protocol, domain name, and port (for example: https://www.example.com). Allowed origins must use the HTTPS protocol. If your website will be making HTTPS calls to Login with Amazon, that is when the allowed return URLs come in. The Return URL includes the protocol, domain, path, and query string. The Return URL protocol must be HTTPS. For example: https://www.example.com/login.php.

Setup

Here is a simple rundown of how to use Localtunnel:

  1. Install Localtunnel globally (requires NodeJS)


    npm install -g localtunnel


  2. Start a webserver on some local port (assuming your local files are accessible through https://localhost)


    lt –-port 80


  3. Receive a random url (you can also use custom subdomains, later mentioned in the article) that you can share with anyone

    For WordPress access, navigate to your tunnel's URL, followed by the name of your WordPress directory, and then append /wp-admin


    https://yourdomain.loca.lt

    https://yourdomain.loca.lt/wordpress/wp-admin


Features

Here is a list of features Localtunnel provides:

  • Secure https for all tunnels
  • Show your work to anyone
  • Use the API to test webhooks
  • Test your UI in cloud browsers


Using a custom subdomain

One great feature of Localtunnel is that you can use a custom subdomain without having to pay for it. Here is how to use it:

lt -p|--port 80 -s|--subdomain yoursubdomain

Possible issues

Redirect loop problem

If you are looking to use WordPress with this Localtunnel, you might run into some problems, for example a redirect loop that won’t let you open your Wordpress site as a admin.

To fix this issue, you need to configure your code in the wp_config.php file. Simply add this code to your wp_config.php file:


define( 'WP_HOME', 'https://yoursubdomain.loca.lt/wordpress' );
define( 'WP_SITEURL', WP_HOME );

define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
    $_SERVER['HTTPS']='on';


This should fix the problem and now you can use your Localtunnel on your Wordpress site with no additional issues.

Your subdomain doesn’t work anymore

It is possible that your subdomain won’t work and it will give you a random subdomain and we don’t want that. The problem is that their servers didn’t fully close the tunnel yet. That might be a problem you cause with not shutting down the tunnel properly, so if this is an issue, you just need to wait for a few minutes and the server will close the tunnel with your subdomain and you can then open another one with the same subdomain.

List of Localtunnel arguments

This is a list of all the arguments in Localtunnel:


Localtunnel arguments

Conclusion

Localtunnel is a great tool to make your local server accessible from the internet. It is very easy to use and has little to no problems. Localtunnel is very secure, and, the best part, completely free.