Playing
01. Exposing your local web server

Episodes

0%
Your progress
  • Total: 3m
  • Played: 0m
  • Remaining: 3m
Join or sign in to track your progress

Transcript

00:00
If you've ever wanted to expose your local web server so you can use it over the internet with a URL, I'm going to show you how to do this with a service called ngrok. So the first question is why would you want to do this? One of the main reasons why you're developing is if you have external services that rely
00:21
on communicating with your project, obviously you don't want to have to keep pushing it up to a production or staging server to be able to test this. So this URL here actually mirrors what I am doing locally. So if I just hop over to my text editor and modify this file, you can see that not only
00:42
changes on my local machine, it also changes with this URL just here. The other reason is you might just want to very quickly boot one of these up, give it to someone and let them take a look and then you can go ahead and close it off. So the benefit of doing it like this is much more secure because you don't have to permanently
01:01
open this up on your machine which is obviously a security risk. So we're going to be using ngrok to do this. So what I'd recommend you do then is sign up for ngrok. Go ahead and download this executable and then place it somewhere that you know that
01:16
you can run it. Of course you can add it globally as well. So what you're going to need to do the first time that you run ngrok is sign in with your credentials.
01:26
So I already have this set up. So when I run ngrok just here, you can see that I have a list of commands. We also get some examples here. Now this is extremely straightforward.
01:37
So once you are in the position where you can start to run this, we're going to go ahead and expose this just here. So I'm going to close this one off and at the moment I'm using MAMP on my Mac but of course this is going to work for things like WAMP or XAMPP.
01:51
It really doesn't matter. Now if you're using something like Laravel Homestead or another virtual machine, this process is going to be slightly different and we have another video covering that. So either way, I'm running on localhost on port 8888.
02:06
So all I want to do is go ahead and run ngrok. I want to run HTTP and then I want to run the port that I'm running on. So in this case it's 8888 and this will boot this up. It will go ahead and give us a one-time URL.
02:22
So when we close this off, this will no longer be available so you'll need to keep this running in your terminal. And if we just go and duplicate this over, paste this URL in and go over to some project, you'll see that we get this just here.
02:37
That is how easy it is. So obviously there are a ton of more options that we can do with ngrok. We're not really going to cover them because in most cases you don't need them. This is really all you need to get this up and running so you can use your URL either
02:51
through webhooks or giving it to someone else. And that is it. We can expose our local machine when we don't need it. We can simply close this off and it no longer works.
1 episode 3 mins

Overview

Need to share a local project you're working on? Or test a webhook from a server? We have you covered with this quick tip.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!