So this is my first post, and I thought I would write something interesting and simple. Ever since I started using internet I always wanted to create my own website. Specifically I wanted to create a website on my laptop. I know there are some hosting services which is entirely free. But what is the fun in that?? In this post I will walk you through how did I host my first website on my machine.
And for your information this is not a perfect way to set up a website as far as I know. But this is just a fun thing to do for beginners like me. And before everything gets started I have to warn you there is a certain level of risk involved in hosting a website on your machine, since we are practically giving strangers access to your computer. I am not really sure about those risks, that's what they say on all the articles I found and I think its true. In my experience with HTTP server I don't know what are the risks, but when I hosted a ssh server , I found that on day one itself there were some access request to my server from unknown IPs. Anyway we are not going to discuss about ssh servers but HTTP server which we use to host the website.
Ok!!! Enough talking and let's get started. So first things first, what all is required. A computer that can be kept online for 24/7 ( or at least when you need your site to be available), a working internet connection. And I used raspberry pi to host my site since I couldn't keep my laptop home for 24/7.
First thing you need to do is set up a web server on your system. I used Apache for setting up my web server. If you are using Ubuntu you probably might have the Apache loaded already. Anyway in case of the raspberry pi it was not. So first I had to install Apache using the command
sudo apt-get install apache2
You can use this command in both raspberry pi and Ubuntu. Once you have finished installing that you have actually created a server on your system. Now let's see if it's up and running.
sudo service apache2 status
This will show us if our server is active or not. And if it is not active use command
sudo service apache2 start
now you have your server up and running. If you open your browser and type "localhost" in address bar you would get a page like below.
First image is page you get when you set up server on pi and second one on an Ubuntu loaded laptop. Cool thing is now you can access this page from any device on your local network by simply typing in the ip address of the server machine on your network.
Now let's see how we can set up a webpage. So that we can change default page doing now. I will be creating a simple webpage showing "HELLO_WORLD!!!!". For that you need to go to /var/www/ and create your website there(we will just delete the index page that already exists which is our default page shown before). And you will be needing root permission to access the files in this directory
sudo rm index.html
sudo vi index.html
Now create a simple html page to display what ever you like and in my case "HELLO_WORLD!!". And after saving it open your browser and enter your IP. You should have your webpage displayed on your browser
Yeah it's cool. We get a page that can be accessed from any of the device in our Network. But that's not enough when we say host a website, right? Of course we need it to be available on internet to call it hosting. So we are gonna do that. But this is the stage where things are gonna get a little bit tough.
I will continue with it in my next post.