Welcome, everyone. It is the second part of how we can setup Linux Web Server and host website on our own Computer. There are some prerequisites to hosting Linux Web Server that we talked about in part 1. If you've not installed Apache web server or any other prerequisite then you must visit Part 1 before reading any further. In this article, we will show you how you can easily make your local website available for the rest of World! So let's get started.
In the first Part, we installed all the tools that are required for setting up Linux web server. We were able to run info.php website that we created using PHP. Was that boring? Well, no problem. In this article, We will host a pretty basic HTML site. I'll host it on my own laptop and provide you the URL. I'll let the server run for a sometime (for some 3 days...) so that you can see everything is working properly. If you are reading this article after this period and also have some problems then comment the problems below, I'll solve it. If you say I can run the web server later as well.
What are we not going to cover when setting up Linux web server?
Most of the tutorials that I found on other websites were too complex for people to set up their own Linux web server. They covered things like, setting up static IP, port forwarding, virtual hosts and so much more. These topics won't clear until one really studies about them deeply. For example, setting up static IP is a complete mess. If you setup static IP in Linux or even on other OSes, most of the time Internet does not work. Just google 'after static ip' and see the suggestions. People have been facing problems with Internet after setting up static IP.
One more thing, if you fail to setup static IP, you can not follow any further steps. So other things like port forwarding and virtual hosts etc. will be useless after failure of getting static IP.
What are We going to cover to setup Linux web server without problems?
What we're going to do is really the easiest way to setup a web server on Linux. There are few things that I think you should be aware of, though not necessary for the success of tutorial but I suggest you read it.
When you setup a web server on your own Linux box, people can only access it using the IP address. And all of us know that the IP address keeps changing. In a day we're allotted many IPs so if we host a web server with this problem, no one will be able to access our website after few hours or even minutes. So we need to setup static IP that does not change. But, here is another solution to this problem. As I mentioned above that setting up static IP can be a mess so we will not go for setting up static up. Rather, we'll update the changing IPs with the web server and allot a URL or domain. So whenever IP changes, a small client updates the new IP with domain and we have working website after months, years and forever until that tunnel is running.
ngrok, Easiest way to make localhost available online
There are many services out there but I use ngrok for it's easy to use client. Ofcourse basic services are free! What ngrok does is create a secure tunnel to your localhost. When you run ngrok client, it binds your IP with a URL and forwards all the request to your localhost. This way, when someone visits the URL, the request is forwarded to localhost. Whenever the IP changes, the client updates it quickly so website is always up.
How To Use ngrok To Make Linux Web Server Online?
It's easy. Firstly visit ngrok website and download ngrok client for your Linux machine. Be sure that you select the right architecture (64bit or 32bit).
After download is completed extract it somewhere on your computer. For ease of access I extract it in my home folder. Now open terminal and run the following command to create a tunnel to your localhost.
./ngrok http 80
Warning - Apache web server that we setup in part 1 by default runs on port 80. But, if you changed the port, then please enter that port # in the above command instead of 80. For example, if you changed port to 90 then use command
./ngrok http 90
ngrok assigns a URL to the localhost automatically
As you run the above you will the terminal screen like this -
Hurrah! Now it has successfully created a tunnel to your localhost. There are two URLs that goes to the same website that we hosted on our computer. The second URL is https version.
Just copy the URL from terminal and past it into browser from any part of the world! You'll see your hosted website. Now just take a deep breath and relax. You've hosted your own Linux web server. Now as longs as the client is running, your website is running. If you stop the tunnel then restarting tunnel will provide a different URL. Though you can have your own custom URLs with subdomain but it is paid. You can also reserve a URL that will not be assigned even if you stop your tunnel.
I hosted a website using the same method and it's running on my laptop. You can check it up.
Paid plan allows you to run multiple tunnels simeltaneously. Let you assign manual URL and reserve a URL and some more features. Just visit their plans page for information on plans.
This is all in this article. In the next article I'll show you how you can start a secure tunnel with ngrok, how you can stop a tunnel to stop web server and some more interesting things that will help you manage your web server easily. If you have any problem then please leave it in the comment section below. If you like this article and the previous one then share it with your friends and family. Sharing helps other learn useful stuff.
Most Read Articles
Translate Our Site
Notice : Please be careful, after translation commands will change.
This website uses marketing and tracking technologies. Opting out of this will opt you out of all cookies, except for those needed to run the website. Note that some products may not work as well without tracking cookies.Opt Out of Cookies