Website on a raspberry pi ? Yes, it's possible

October 13, 2016

Last month, my article my resume as an operating system made a buzz during one week.
Thanks for your interest !
By the way, this buzz has forced me rethink my webserver. My personnal server has enough power (4 cores, 16GB RAM, 2 hard drives RAID 1). The main problem was my internet connection.

Now, my problem is solved thank to CloudFlare.
This article is not my solution, but an idea. Many people uses Raspberry pi as server (webserver, files, media sharing...) but in fact it is not appropriate to.

CMS to static

A pure developer (or geek...) think that a CMS is the evil... In my opinion it is a fantastic tool ! I use Ghost platform (running in a docker container).

Last month, while I was looking to Apache log files I saw many people (or robots ?) testing standard administration URI. The best security is to make a static website while keeping my Ghost platform as a publication tool.

It is very simple, wget utility has a "recursive" option :

wget -r -np https://www.mathieupassenaud.fr  

-np

Do not ever ascend to the parent directory when retrieving recursively. This is a useful option, since it guarantees that only the files below a certain hierarchy will be downloaded.

-r

Turn on recursive retrieving. The default maximum depth is 5.

A CRON job do this work for me. Now, my Apache configuration is not a proxypass ; a basic configuration to a static website. This is the best security.

Raspberry PI : Not for storage

With this affordable computer, you have the choice between 2 storages :

The best storage ever is RAM, my entire website fits in 22M :

mathieu@portable:~/site$ du --max-depth=1 -h  
22M    ./www.mathieupassenaud.fr  
22M    .  

A Raspberry PI 2 has 1Gb of RAM. This is enought.

First of all, I disabled everything except a SSH server and nginx.

I pushed my static website to /var/www/html, no special configuration.

I made some performance tests (see bellow), then I created a ram disk (tmpfs, not ramfs) and mounted it on /var/www/html, after that I copied all files.

mount -t tmpfs -o size=100m tmpfs /var/www/htmt  

Performance test

Hardware :

I use Apache Jmeter.

10 users, 3 seconds to load and 10 iterations.

Here are 4 comparaisons :

Apache

Ghost (NodeJS)

Indead, static files provides better performance. Easy to understand, however some people said that node is the best implementation ever.... :-)

Stored on SD card

In RAM

No coment ? hum... note that Ghost is slower than a SD card in a raspberry pi ^^

50 users, 3 seconds to load and 10 iterations.

apache

ghost

SD card

RAM

Conclusion

In fact, there is no software optimisation. It was a pure hardware test.

A Raspberry PI can server as a webserver, for static file directly in ram it is realy powerfull.