Saturday, March 17, 2012

Turn your PC into a Web Server and host your web-site for free


In this article, I am going to explain how to use your computer with Internet connection as a Web Server to host your own web-site.

Overview

Generally, if you want to host a web-site, you need to either buy a domain or look for some free web hosting services.You put your web-site's code there and then it can be accessed from anywhere through Internet. This way, whenever you type in the address of the web-site, it is redirected to that server's location (its IP address) and its corresponding port (which is mostly port 80). So, if we want to say, host our web-site at home, we need to make sure that whenever someone types your IP address, it should reach your PC's localhost server.

If you don't know anything about IP address, Port, DNS etc, please go through following links before reading this article. It will help you in understanding this article better.

Internet Protocol (IP)
Port Numbers
Domain Name System

Now, the things you are going to need are :

1). A PC with an Internet connection
2). Global IP address
3). Any web-server software

Set up your web-server 

To host a web-site at your home, first thing you need is of course your web-site running on your own PC. I use Apache-Tomcat for this as it is free. Other web servers are WAMP and Oracle etc. You can use any of them. All web servers run on a specified port no, which can be configured from the web-server settings (for Apache Tomcat, default port no is 8080). After starting your web server, start your web site on the server. You can check if your site is working or not by typing localhost/your-website-link. This depends on the configuration of your web-site and web server. So after this step, you are able to view your web-site on your own PC.

Next thing is to make your web-site accessible to the whole world so that when anyone type your IP address with appropriate port no, the request should reach your local server to corresponding port no. For this, you must have a Global and preferably a static IP address. So, you need to determine that whether your IP address is local or Global. Check your IP address by going to command prompt and typing IPconfig (in Mac OS, you can do this by going to Network Utility ). Also, go to google and type "what is my IP". If in both case your IP is same and your IP address is "NOT" in the following IP ranges, it means that you have a Global IP address.


10.0.0.0 through 10.255.255.255
169.254.0.0 through 169.254.255.255
172.16.0.0 through 172.31.255.255
192.168.0.0 through 192.168.255.255

If you have a global IP address, you just have to type in aaa.bbb.ccc.ddd:portno/your-website-link and you will able to access your web-site from anywhere as long as you keep the web-server software running on your PC and your IP doesn't change. If you have Global IP address, you can skip the next step and continue reading.

In this Video, I have explained how to start Apache Web Server and run your web-site on localhost. For testing purpose, I have created a simple page named "test.htm". After starting the Apache web-server, this page can be accessed from localhost

Port Forwarding

But, if the IP address you found from Google is different then the IP address that you found in the command prompt (for e.g., 192.168.xxx.yyy ), it may be because you have a routing device somewhere which creates a personal network.It assigns local IPs from above range to all the PCs connected to the router and then connects that network to Internet through the Global IP address. In this case, whenever someone types your IP address, it reaches the routing device instead of your PC. So, the web site that is hosted on your PC is not accessible from Internet. To overcome this problem, most routing devices have a facility called "Port Forwarding". Like its name suggests, it forwards requests on specific ports of router to your local IP address. This way, if your local IP address is 192.168.xxx.yyy, and the web server is running on port no 'dddd' , you have to 'tell' your routing device to transfer all the request on port 'dddd' to your PC's IP address (i.e. 192.168.xxx.yyy in this case). Most routing devices have this functionality inbuilt and it can be enabled from your router configuration ( to change router configuration, refer to your router's user manual ). After you have enabled port forwarding, rest of the process is same. You can access your web site by simply typing ppp.qqq.rrr.sss:portno/your-website-link, where, ppp.qqq.rrr.sss is your router's IP address and portno is the port no on which the web server is running.


In this Video, I have explained how to enable Port Forwarding in case you have a local IP (192.168.1.100 in this case) address. After enabling Port Forwarding, you will be able to access the localhost from the Internet using the Router's Global IP address (124.125.158.5 in this case).

Setting up DDNS

So till now, you are able to access your web-site from anywhere using global IP address and port no of the web-server running on your PC. This works well, but you have to type numeric IP address which is hard to remember. Also, problem with most of ISPs is that they provide a dynamic IP address. This means that your IP address keeps changing from time to time. So, every time your PC's IP address changes, link to your web site changes. For these problems, DDNS is the best solution. DDNS stands for Dynamic Domain Name System. Basically, DNS is the service that gives a "name" to IP address and DDNS is a service that can be used to provide "name" to dynamic IP address. This way, by using DDNS, you can access your web-site with yourname.something.net even if your PC's IP address keeps on changing. Both free and charged DDNS service providers are available. Here, I am going to explain free DDNS service NO-IP.com and how to use it.

Go to No-IP.com and sign-up there. After you have signed up, login with your credentials. After you login, click on "Add a Host" and fill the form. In Hostname, write any name that you want to use and choose any of the free available domains (various domains that NO-IP.com provides are : "zapto.org", "ddns.me" , "sytes.net" etc.). In the host type, select "Port 80 Redirect". In the IP address field, write your Global IP address and in port no, write your web-server's port no and click on "Create Host". After that, wait for five minutes for changes to take effect.

Now you can access your web-site just by typing "yourname.zapto.org" or "yourname.ddns.me". This address will work till your IP address does not change and web-server is running on your PC. There is one last step in this process to make this address valid even if your IP address change. To enable this, go to NO-IP.com and go to downloads page (https://www.no-ip.com/downloads.php) and download the version that is suitable to your OS. After downloading it, install the software.After finishing installation of the software, start the software. It will ask for credentials that you use to login to NO-IP.com. Enter the credentials and log-in to the software. On logging in, it will display the name of the site that you just created (i.e. yourname.zapto.org or yourname.ddns.me ). Select that name and click on Save and minimize the software. This software constantly monitors your IP address and whenever it changes, it informs such change to NO-IP.com, which changes the association of "yourname.zapto.org" to newer allocate IP address.


This video explains how to setup DDNS using NO-IP.com's free DDNS service. NO-IP.com provides free DDNS client to monitor your dynamically changing IP.


So, that's it. You have created your own web server which can be used to host your web sites and that too for absolutely FREE.

Download :

1). Apache Tomcat web server
2). NO-IP.com's free client software

If you liked / didn't understand / have questions about this article, post a comment here or write to me on dmehta17@gmail.com. You can also reach me through Facebook on www.facebook.com/damehta.

19 comments:

  1. Wow, I didn't know this could be done with a dynamic IP. You wrote your explanation very well.

    ReplyDelete
  2. Hey, I have one question:

    Isn't 192.168.1.100 also dynamic ip? it keeps changing.....

    Is there a way to configure it??

    ReplyDelete
  3. Use DHCP reservation.... it will book the ip for particular MAC address. type in cmd:- getmac. next goto 192.168.1.1 and on the first page click on dhcp reservation. add the client name, desired ip and then mac address you got from cmd...

    another thing - DAM, you rock.............

    ReplyDelete
  4. Hey it worked for quite a few days and then suddenly stopped! REASON?? DAM?? Please help urgent - I have an assignment to do on this!!!!!!!!!!!

    ReplyDelete
    Replies
    1. Sorry for late (I know, it's too late.. about 4 months late) reply...

      You can start with checking port forwarding first.
      After that, check whether you are able to access the server locally. (i.e. by typing 'http://localhost:[PORT_NO]/[SERVER_INSTANCE_NAME]' )

      Then check whether your server is accessible from another computer by using your IP Address.
      If all the metioned things are working, then I think there is a problem with your DDNS settings. Configure them again and it will work.

      Delete
  5. Hey DAM,

    I am using reliance netconnect(my ip is global). The site is working with localhost/your-website-link. But it is not working for me when i try it from other machines. Any idea what might be wrong?...

    Thanks

    ReplyDelete
  6. check whether you are able to ping to that IP address by writing 'PING ' in command prompt and checking the result. If you are able to get the response, then there may be a problem with your firewall / Web Server. Let me know which server are you using.

    ReplyDelete
  7. Thanks. Its very nice article.

    ReplyDelete
  8. Dhaval Mehta, you are my life saver... was looking for this kind of set-up from past few years....

    Thanks a lot

    ReplyDelete
    Replies
    1. Hi DAM,

      I have follwed your instruction, with using localhost/testapplication and mypublicip/testapplication both are working on my local machine, when tried using them on another machine its not accessible.

      Tried to ping mypublic ip from my local machine works fine, but no luch from another pc,

      I am using Tomcat 7 on windows 7 server.

      I guess something to do with FireWall settings, Could you please help me here.

      -Anil Katta

      Delete
  9. hi i have window 7 and tomcat 7 installed and i deployed my java application on tomcat server my http port no is: 8082. my pc is not connected with any LAN and not with any router setting. i simply connect the internet with vodafoneIN through data card and my public ip on google search and from cmd prompt by typing IPconfig is not matching...what to do...

    ReplyDelete
  10. Thnx buddy... it worked really well...

    ReplyDelete
  11. I would but say to you all "impressive information" www.bsdrouter.org

    ReplyDelete
  12. A very good article indeed. Yet we need more than this.

    email hosting services

    ReplyDelete
  13. Nice Blog. Thanks for sharing with us. Keep Sharing!!

    Do you want to Buy Resistive Touch Controllers Online?

    Buy Resistive Touch Controllers

    ReplyDelete