Hari's Corner

Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and then

Linux self webhosting - HOWTO

Filed under: Tutorials and HOWTOs by Hari
Posted on Fri, Apr 13, 2007 at 14:28 IST (last updated: Thu, May 7, 2009 @ 21:00 IST)

In this series < Previous
In order to explore self-hosting, I decided to get myself a dyndns.org host name and find out how the whole thing works. This HOWTO is based on my own experience.

Setting up a simple home webserver is extremely easy. Instead of going with Apache, try something like boa. Not only is it very simple and lightweight, it normally requires no configuration at all. Even if you need to tweak any settings, its configuration file is very simple and easy to understand. Only if you need a lot of features or you're hosting dynamic pages like PHP, ASP or JSP you should use a more powerful server.

Here's a simple home website hosting how-to. I'm assuming that you have are behind a router. If you aren't and you have a permanent external static IP address for your machine, then it becomes even simpler (just avoid the port-forwarding step).

Step 1: Install a safe firewall configuration

In case you're not behind a router, you would need a firewall to block services not absolutely required for the outside world. If you are behind a router, then you won't need a firewall, but I still recommend one just as an added layer of security. A good idea would also be to simply disable any services running on the system which are absolutely not needed.

You don't absolutely need a firewall if you don't have any other services running on your machine which you don't want to expose to the outside world.

Guarddog is a great GUI firewall program that can configure an iptables firewall in double quick time. Install it and configure your firewall. The GUI is extremely intuitive and you won't need to know anything more than what services you want enabled (both incoming and outgoing from your machine). Make sure that all the services you need are enabled in the configuration and then apply it.

While configuring make sure you enable HTTP from local to internet zone.

If you're good enough to use iptables directly, then you may not even need my help ;)

Step 2: Install a webserver

There are many webservers you can use. If you're not really comfortable with Apache or simply don't need its added power you can install a really light-weight, no-frills webserver like boa or lighttpd.

If you're a user of Debian or Debian-based distros simply type:
apt-get install boa
From the command line and you're done. Or use the package manager of your distribution to get it or simply compile from sources.

Now make sure your webserver is working properly by typing http://localhost on your browser window. You should get whatever is the default home page of your webserver.

Add a index.html file in /var/www/ directory. You can also create a public_html directory in your normal user's home directory. You can access this by typing http://localhost/~user. Add whatever other web pages you wish to serve in either /var/www or (if you've enabled user directories) /home/user/public_html where user is your user name.

Step 3: Get a host name at DynDNS

Although you can set up your own name server if you have a domain name, you can also use DynDNS which is very convenient for dynamic IP hosts. Create an account. Log in and click on the "Dynamic DNS" link and click on "Add host." Type in the name of your website and choose an appropriate domain name (you have plenty of choices) and add it. Your current IP address will get hooked to it. That's all! You're now almost ready to host your website. If you have a static IP, you should probably create a "Static DNS" instead of the dynamic one.

Step 4: (If behind a router) Port forwarding

You can avoid this step if your machine has a direct static IP to the internet. Most likely in a home system, this is rare. If you're connected to the internet using any router, you need to follow this step.

This is the trickiest part of the whole setup. But don't worry. If you're using a router, then you need to get into the web administration panel of your router. Open a browser and type the internal address of your router (usually http://192.168.1.1) You will be prompted for the username/password of your router to proceed further.

Say your local machine IP is 192.168.1.10 and your router internal IP is 192.168.1.1. Your machine is like a client in a LAN and you need to make sure it can be reached from the outside world. Port forwarding is how you do this. By forwarding different ports, you can enable different services from your machine to the outside.

These are the general settings you would need to set in this screen: Once you apply these changes, the router will probably have to be restarted.

On some routers, this setup is also called Virtual Servers instead of Port Forwarding. Only enable the services you need to be forwarded in this set up.

Step 5: Testing it all out

Since you're behind your own webserver, you cannot test whether everything works well from your this system. Get another internet connection on a different PC and check the URL (which you created with the DynDNS account) in a browser.

If everything has worked well, you should see your own home page now. Congrats. :) If something is wrong and it doesn't work out, you should probably check whether you've done the previous steps properly.

To access your website from the server itself, you should probably type http://localhost in your browser window. ;)

Finally some points to note

Hope you found this guide useful. If there's anything you need clarification on, do ask!

In this series

5 comment(s)

  1. Excellent guide, Hari! Such a setup - using DynDNS - is also very useful for accessing your network using a VPN or otherwise when you're on the run :)

    Comment by J_K9 (visitor) on Fri, Apr 13, 2007 @ 16:03 IST #
  2. Yeah, I know, it has a variety of uses and purposes. DynDNS is a potent tool.

    Comment by hari (blog owner) on Fri, Apr 13, 2007 @ 17:10 IST #
  3. I've incorporated your suggested changes, Max. :)

    Comment by hari (blog owner) on Fri, Apr 13, 2007 @ 17:17 IST #
  4. Another good resource if you want to host yourself on your home connection and you actually have a domain name registered is zoneedit.com which is free DNS of up to 5 zones (domains). After that or if you need more, you pay for each zone.I did this for my own servers using my home connection until I finally broke down and got me real rackmountable servers to place in an actual colocated data center.

    Comment by drew (visitor) on Fri, Apr 13, 2007 @ 21:12 IST #
  5. Drew, thanks. I will take a look at that too.The biggest impediment to self-hosting personally is actually keeping a dedicated machine running 24x7 reliably. Cannot do it myself since I don't have a dedicated machine and secondly I cannot afford the bandwidth costs (I don't have unlimited bandwidth)... :smile:

    Comment by hari (blog owner) on Fri, Apr 13, 2007 @ 21:37 IST #

Comments closed

The blog owner has closed further commenting on this entry.