How To Setup Linux Web Server And Host Website On Your Own Computer [Part - 2]

Sohail
Sohail

Table of Contents

setup Linux web server

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 the World! So let’s get started.

In the first Part, we installed all the tools that are required for setting up a 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 some time (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 on 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 a static IP is a complete mess. If you setup static IP in Linux or even on other OSes, most of the time the Internet does not work. Just google ‘after static ip‘ and see the suggestions. People have been facing problems with the Internet after setting up static IP.

issues after 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 the 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 a few things that I think you should be aware of, though not necessary for the success of the tutorial 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 a 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 a working website after months, years and forever until that tunnel is running.

​ngrok, the 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 the 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 the download is completed extract it somewhere on your computer. For ease of access, I extract it in my home folder. Now open a 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 the 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 go to the same website that we hosted on our computer. The second URL is https version. Just copy the URL from the terminal and past it into the 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 are 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 a subdomain 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.

5a1851dd.ngrok.io

my website on linux web server

​The paid plan allows you to run multiple tunnels simultaneously. Let you assign manual URL and reserve a URL and some more features. Just visit their plans page for information on plans.

Conclusion

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 the 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 others learn useful stuff.
Uncategorizedhow-to