How to run a linux based home web server

Posted nine years ago

There are plenty of places you can go if you just want to put up some static web pages for free, or very low cost. But costs go up very quickly if you need to do any more than that, or if you get spikes in traffic. Sometimes you need complete control over the server, and don't want to pay $20 to $40 a month for a VPS. In this article, I'll describe step by step how to set up a home web server using Ubuntu, capable of handling modest spikes in traffic.

There are several things you need:

Connection

Hardware

Domain name

DNS server

Web server software properly configured for your system

The Connection

Many large internet providers forbid running any servers in their usage agreement. They might not actually check for a long time, but it's no fun to have your Internet cut off without warning after months with no problems. You can only do this if you are lucky enough to find an ISP that allows servers. In Canada, try Teksavvy.

You will want as high an uplink speed as you can get. Unless your website is extremely popular, bandwidth caps will not be an issue, but be aware of what they are.

The Hardware

Over your home internet connection, traffic will be naturally smoothed by the low uplink bandwidth. Incoming requests will be queued and served in order, not all at once. CPU speed is not going to be an issue, and a one GHz machine is plenty of power. Although this blog's web server has only 512 MB of memory, I recommend at least 1 GB of RAM.

Your router will also be an important part of the system, but quality varies. I have a Linksys WRT54GL. I downloaded and installed dd-wrt on it. The new firmware unlocks a lot of hidden features, including dynamic DNS updating. However, this is not strictly necessary, because your linux system can handle this step just as easily.

Domain name

You can get a domain name for 10 to 15 dollars. Try DomainsAtCost or GoDaddy. After you buy one from a registrar, you will get an account with them. After logging in, you can renew the domain name. But the most important priviledge is to be able to set the name server. That will have to wait until the next step...

A few months after getting your domain name you will start getting emails from companies claiming they have registered it in another country, and offering to sell it back to you. You can safely ignore these scams.

DNS server

Because your IP address will often change, you will need a dynamic DNS updating service. DynDns.com provides very good service, with updates taking effect within seconds. However, they do charge a fee. ZoneEdit provides a free service for up to five domains, although updates can take several minutes to propagate.

After signing up with a dynamic DNS updating service, you will get:

a username and password

IP addresses of nameservers

Save the username and password for later. Go back to your domain name registrar and enter the nameservers into their system.

Configuring your server

Install the latest Ubuntu Desktop edition, and then add the additional software you will need for web serving:

After a few minutes you should be able to get to your web server by entering your domain name. If things aren't working, running 'sudo ddclient --verbose' will help you figure out what it's doing.

Configuring Apache2

There is one last thing. Because your machine has limited memory and bandwidth, you will need to set some parameters in /etc/apache2/apache2.conf.

The KeepAlive setting keeps your server busy for a few seconds after a page is served, allowing clients to download images without starting a new connection. The default setting is far too long, and it would cause your server to choke under heavy load. Set KeepAliveTimeout to 1 or 2 seconds.

The MaxClients setting determines how many connections your web server can handle at one time. Each connection takes around 5 megabytes of unshared RAM, so you will have to set this value taking into account the amount of RAM on your machine, while leaving room for other system processes. For 1 GB, a nice safe value is 130, but your mileage may vary. If your server becomes unresponsive, reboot it and lower this number.

After any change to server settings, use "sudo apache2ctl restart" to safely restart everything. Your users won't notice a thing.

Optimize for bandwidth

When your bandwidth is limited, the number of visitors you can handle is directly proportional to size of the page, and all the images. If you have 120 KB/s of uplink bandwidth, and your page is 120 KB in size, then you can handle no more than one visitor per second. The single most important thing you can do is make your images as small as possible. Use low quality JPG for photos, and 32 or 256 colour PNG files for everything else.

Include all your own CSS and Javascript in the same file as your HTML, so that only one page needs to be requested. During times of heavy load, 99.9% of your visitors only load a single page of your web site anyway, so it makes no sense to split things up into different files.

In conclusion

If you need 99.999% reliability, you should look for a hosted VPS solution. However, for modest needs, you can achieve 98.9% reliability for no cost other than what you are paying your internet provider.

Just a question, I am trying this myself using an old PC and either Ubuntu or Centos, (any recommendations?) My question is, if I use a DNS service and register one of my old domains, can I know use this domain as a namserver and add more domains to point to my server?

One very real cost that you're overlooking is cost of the power consumed by your machine. This can add up to a considerable amount over the month, surpassing the cost of a cheap VPS provided (e.g $15 per month)

For a micro-ISV, selling to businesses can be more lucrative than selling to consumers. Instead of making a few dollars per sale and hoping for thousands of sales, you sell to only a few customers, and charge much higher rates. But the rates are high for a reason. It takes more time and money to sell to businesses.

If one apple costs $1, how much would five apples cost? How about 500? If everyday life, when you buy more of something, you get more bananas for your buck. But software companies are bucking the trend.

Much ink has been spilled about the use of cell phones on airplanes. Here's the truth, which will be disappointing to conspiracy theorists: Cell phone signals most definately have an effect on other electronic equipment. Read on for more.