One thing I hated about WebHostingTalk is
how much bad advice the so-called “professionals” are giving out to the
world. Some poor college student asked in the VPS forums whether he is able to run 18 static HTML sites onVPSLink.com Link-1 plan (64MB RAM, 2.5GB storage & 100GB/month data), and the typical responses are:
“I do not believe you can host 18 websites on 64MB of RAM. I’d bump that up to at least 128 or 256.” –nexbyte
“I really wouldn’t advise anything lower than 265MB RAM for website hosting.” –RikeMedia
(Well, there are some more optimistic comments but I mainly list out those “with things to sell”)
So, just trying to prove the point that yes, 64MB is more than enough to host 18 static sites, I decided to add aLink-1 Xen to my account and document the process. Btw, thanks to Dan @ VPSLink for getting my billing issue resolved :) You can get 10% recursive discount here, or 66% off for the first 3 months here.
Setting Up the VPS
After my order has been provisioned, I re-image the server with a Debian
5 “Lenny” image. I normally pick Debian or Ubuntu because
apt-get
uses
much less memory than RedHat/Fedora’s equivalent, and it’s also my
personal preference. I named my new VPS “endor” as I usually just name
my boxes after Star Wars systems.
Re-imaging a VPS is pretty fast — 2 minutes later I have my root
password sent to my email address so I can ssh in to set up the new
system.
Plenty of free memory and a single core of C2Duo E4500 —
although not a high-end Xeon CPU, but should be more than sufficient to
do what we need it to do. The next thing I want to do is to make sure
every package is up to date.
Setting Up Web Server
Okay. The 64MB VPS is now up and running. What should we do next?
Installing a web server of course, so we can start serving our static
pages! Which web server? Definitely not Apache as it would be a waste of valuable memory here. Again my personal favourite is Nginx (pronounces Engine X), which currently powers LowEndBox.com. However, in this exercise I will go for Lighttpd because I found it easier to set up for abitary sites.
First of all — get Lighttpd installed.
Plain vanilla stripped down and un-configured 32 bit Lighttpd sits around 1MB RSS — not bad.
Next, we need to get our websites up there and point Lighttpd to them.
It’s a good idea to put the web sites in an organised structure inside
the file system. I usually just place them this way:
/var/www/<hostname>/html
So if I have an HTML file at http://www.example.com/testing.html, it will sit on the file system at
/var/www/www.example.com/html/testing.html
.
Unfortunately I do not have 18 static sites. For testing purpose I am
only going to display a very basic HTML page at
http://test.lowendbox.com/.
So now our “website” is ready — how does Lighttpd, our webserver, knows
where to find the files corresponding to the website? That’s where
Lighttpd’s mod_simple_vhost comes in handy.
Now navigate to test.lowendbox.com (which already has an A record to my
new VPS’s IP address) — here we have it! Low End Box Rocks!!!
Prerequisite:
You must be already familiar with DNS and know how to create records to point to IP addresses. For free DNS hosting I recommend EveryDNS, which has also been hosting LowEndBox’s domain.
You must be already familiar with DNS and know how to create records to point to IP addresses. For free DNS hosting I recommend EveryDNS, which has also been hosting LowEndBox’s domain.
You can now basically just dump static files at /var/www/<hostname>/html,
with <hostname> resolved to your VPS’s IP address, and you will
have your static websites over there in no time. You do not even need to
tell Lighttpd to reload, as mod_simple_vhost automatically maps the
hostname to appropriate file name. Repeat it 18 times and problem
solved!
At 1 single testing site with no traffic, Lighttpd sits at around 1.5MB
RSS, although I doubt it would increase significantly when you increase
the number of sites or the traffic. Lighttpd and Nginx are
single-threaded poll-based asynchronised web servers so for static file
serving, the bottle-neck would be disk/network IO rather than amount of
memory or CPU performance.
There are still lots of memory left. Maybe we can have some fun.
Installing WordPress
So you think, “hey Low End Box rocks and it runs on WordPress. So maybe I will have that installed as well!” Wow. But WordPress is a content management system for creating dynamic websites! It simply cannot be possible on a 64MB VPS, the WHT crowd says! Grrr!! Let’s give it a try.
To run WordPress from your static-file serving Lighttpd, you need a few
more packages — namely MySQL and PHP in CGI/FastCGI mode.
I know it installs whole lot of other junks but don’t worry — we will
live with them first and will try to optimise later. It also requires
you to set up the root password for MySQL server, and I conveniently
chose the most obscured password in this exercise — “root” (yes, don’t
use that because I am already using it as my root password :)
We then need to configure lighttpd to handle PHP files.
Done! It should be able to serve PHP files. Just to test it out:
Now navigate to http://test.lowendbox.com/phpinfo.php — you should be able to see the output of
phpinfo()
function. What we are going to do next is to set up a WordPress blog under http://test.lowendbox.com/blog/. WordPress.org already provides a great tutorial on installing WordPress, but let’s do it step by step on the command prompt.
My plan:
- Create database “test_blog”
- Download the latest WordPress and unzip to test.lowendbox.com/blog
- Set up configuration file and run the WordPress install
- Update Lighttpd to provide clean URL, aka Pretty Permalinks.
Let’s go!
When you are editing WordPress’ configuration file, set
DB_NAME
to “test_blog”, DB_USER
and DB_PASSWORD
to
“root” for something quick, dirty and potentially insecure. Here is one
final step — navigate to http://test.lowendbox.com/blog/, and WordPress
will guide you through the rest of setup.
It is also relatively easy to set up pretty permalinks for WordPress on Lighttpd. In our example,
That’s it! You can now go into WordPress to configure the desirable
Permalink Structure. Do note that the current WordPress dashboard page
is very resource intensive, as it fetches development blog, other WP news, incoming links, etc from various sources, concurrently on
separate PHP CGI processes. There might be plugins to turn off this
server-killing behavior (or just use older version of WordPress like
2.0.x which is still maintained). Likewise some WP caching plugin can be
very useful in reducing the load. Google them and you shall find.
Optimisation — Squeeze More Memory!
So now we have a Debian 5 web server box that can handle lots of static
sites + a few WordPress blogs, and it fits “fine” on a 64MB Xen VPS.
Let’s see what processes are running:
Note that it’s an idle box. The swap is slightly used and at 37MB free it is actually not too bad. Let’s try to squeeze a little bit more memory out from the factory setup.
MySQL is by far the biggest offender, and I have talked about how to reduce MySQL memory usage here.
If you are just running simple CMS, InnoDB is probably not required —
it uses more memory and a lot heavier on IO as well. We can simply use
the LxAdmin’s mysql.cnf which I linked on the other blog post to get the
bare-minimum MySQL running.
As
mysqld_safe
script uses /bin/sh
for scripting, it’s also a good idea to check whether dash is used instead of bash.
One thing I don’t like about Debian 5 is its default inclusion of rsyslog.
Well — it’s feature rich, but I don’t need MySQL and TCP syslog
support. Weight at 1.2MB RSS is just a bit too fat I reckon. I am not
game enough to gowithout a syslog daemon, so I just go for syslog-ng. Probably not the most light weight, but it’s just something I have been using for the last couple of years.
Shedding 500kb RSS — not too bad I guess :)
Next — Portmap and FAM got installed when Lighttpd was first installed. Lighttpd does not really need
FAM. It’s used for stat cache to reduce seeks, but can live without.
Not that I have noticed any performance difference anyway for small
traffic anyway. Having both of them removed from the process list would
give us extra 750KB.
OpenSSH can be replaced by dropbear to save memory.
Just remember to set
NO_START=0
in /etc/default/dropbear
so
dropbear can run as a daemon. Dropbear daemon is using around 500KB
less than OpenSSH daemon during idle, and for each connection it uses
1.5MB less on this Debian 5 box — that’s quite a saving!
That’s probably it! Vixie cron can be replaced by a light weight DCRON but
I can’t seem to be able find it in Debian’s repository. Exim4 is
probably one of the most light weight mail daemon you can have, but then
again you might want to question — “do I need a mail daemon running”?
You can probably bring it down, and just run
/usr/sbin/runq
once
every 2 hours to process the queue, in case the previous delivery
failed. That would probably give you another 1MB to play with.
You can also use PDKSH to replace BASH as interactive shell to loose some weight.
That’s 1 full megabyte off the scale! Also note that VPSLink’s
/etc/inittab
automatically
spawn a BASH process on the console — just in case you got locked out
from firewall. For me it’s the last line of inittab
file. Change it to /bin/sh
or /bin/pdksh
, run init q
to reload init(1), and then kill that bash process.
Here’s the end result:
That’s 12MB trimmed, which can be used in disk cache to improve static file serving.
Conclusion
So how do we conclude? 64MB is more than enough to serve a few low traffic static websites.
You can actually run a few WordPress sites with a few hundred visitors a
day — at the price equivalent to many heavily oversold shared hosting and you get root access!
One thing about root access though — in all my examples above I used root account and never bothered to use anormal user account. It is bad from security aspect so don’t do it. Or at least don’t tell anyone that you use nothing but root :)