Raspberry Pi Web Server. Does it work?

Raspberry Pi Web Server in a white and red case

Introduction

For the past few years, I have run a few websites on a Raspberry Pi 3B at home. I decided to do this just because I like to do some general tinkering with gadgets, but also because I thought it would be a cheaper way of hosting websites.

Now I am going to share with you what I have learned whilst using the Raspberry Pi as a web server. You might even want to try setting up your own server.

Raspberry Pi Specifications

First, let’s take a look at the specifications of a Raspberry Pi 3B as listed on the official Raspberry Pi website.

  • Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz
  • 1GB LPDDR2 SDRAM
  • 2.4GHz and 5GHz IEEE 802.11.b/g/n/ac wireless LAN, Bluetooth 4.2, BLE
  • Gigabit Ethernet over USB 2.0 (maximum throughput 300 Mbps)
  • Extended 40-pin GPIO header
  • Full-size HDMI
  • 4 USB 2.0 ports
  • CSI camera port for connecting a Raspberry Pi camera
  • DSI display port for connecting a Raspberry Pi touchscreen display
  • 4-pole stereo output and composite video port
  • Micro SD port for loading your operating system and storing data
  • 5V/2.5A DC power input
  • Power-over-Ethernet (PoE) support (requires separate PoE HAT)

As you can see, the Pi as a relatively low spec device, so you will not want to use this for websites with high volume traffic. Similarly, it works best with static websites as these require less grunt to run. I currently have a couple of WordPress websites running and they sometimes struggle to render the web page. Given the importance of website load times on SEO, this can be a problem.

The concerning issues with running a website on the Pi are the low CPU speed, memory and the storage medium. The slow CPU and memory are the main reason why running frameworks such as WordPress can be problematic. Unlike regular static sites which have all the HTML markup, styling and content contained in a few HTML, CSS and JavaScript files, WordPress has an entire platform of complex software sitting behind the front-end that a website visitor actually sees. Quite simply this is too much for a humble Pi to cope with.

Web server on an SD card?

WordPress and other Content Management Systems read and write to a database. This adds additional work for the Pi to perform before it can render the webpage. These read and writes are being made to the micro SD card, which is a slow performing storage medium. SD cards are great for storing photos on your camera or maybe some MP3 files. Sadly, they do not perform well on a live web server. Quite simply micro SD cards are just too slow and unreliable.

When you can consider why people use WordPress; they want to update content regularly, then you can understand why frequent writes to the card are necessary. If you run a static website then you likely do not want to make changes to the website content often. In this case, you can simply take a backup image after finalising your website content and always have it ready to be reinstalled. However, doing this on a regular basis for a frequently updating WordPress website would just be a pain. You would have to shut down your server, remove the card for imaging and then reboot the server. All this time your website is unavailable. A guaranteed way to be given an SEO penalty by Google.

Furthermore, in my experience, the CPU and memory are not the biggest issues with running a website. I have Ubuntu Server installed on a 32Gb micro SD card. This card is frequently corrupting. Even when using one of the Raspberry Pi foundation’s recommended micro SD cards.

SD Card Solution?

On Pi forums, it’s often suggested that corruption happens when there is a power cut to the server whilst the writes are being made on the card. This may well be an issue but I have noticed that when the server is under high load corruption occurs. No power cuts involved at all.

A possible solution to the SD card corruption problems is to try and reduce the number of writes taking place by disabling logging, but if you are running a live server you really need log files to keep on top of any server related issues.

Another solution is to boot the Pi from a USB device rather than an SD card. Thankfully, this can now be done on some models of Pi. The best option here would be to use a powered SSD drive.

To be extra safe you could also add a battery pack to the Pi to protect against power cuts. A simple power pack such as the type you would use to charge your mobile phone on the move might suffice. You just have to make sure it can be plugged into the wall and the Pi at the same time. Also, make sure you buy this battery pack from a reputable manufacturer. We don’t want it bursting into flames if left plugged in. It is always best to check the documentation to ensure it is safe to leave it connected to a power outlet. If in doubt, do not use it.

There is also an official battery module for the Pi. So it’s worth having a look at that too.

The bandwidth of the network ports on the Pi are generally fine for low-ish traffic websites. Obviously, if you are receiving 500k visitors a month it’s best to get dedicated hosting. But for a small business or a personal website, you shouldn’t have any real issues.

I tend to use the Pi to host personal projects that I sometimes display on the web design portfoio section of my website. There is no real requirement to place personal projects on a premium web host. It saves money on hosting costs, but I always use dedicated premium hosting for client websites and high-traffic sites.

Conclusion

The Raspberry Pi is a great little, low-cost, low-power consuming minicomputer. It has many different applications but generally not really suited to a live server scenario. However, if you like to tinker and save yourself money on web hosting fees then why not give it a try? You might learn a bit about server maintenance, which is a useful skill to have. You just have to be aware of the Pi’s limitations. Essentially, it is fine to use a Raspberry Pi web server for low traffic, static websites. Your mileage may vary when running a CMS on it. But some of the problems can be negated by adding an external hard drive. Obviously, this will add a little extra to your electricity consumption but is generally worthwhile just to have a more stable server.

You could also consider the newly released Raspberry Pi 4, which has a more powerful CPU and up to 4Gb of memory.

I hope you have enjoyed this article on running a Raspberry Pi web server. You can read more of my articles in my Blog page.

Alternatively, you can check out my web design, development and SEO business website.

Feel free to link to, and share this article if you have enjoyed it.

You can also follow me on Twitter or LinkedIn.

© Ian Morrison