Creating and Hosting a Website using a Raspberry Pi

3.10.2020

Beginning on March 12th 2020 all schools and colleges in Ireland closed in an effort to combat SARS-CoV-2, a novel disease which targeted the respiratory system which we would discover on March 14th had 39 confirmed cases in the country. This closure was initially supposed to last until the 29th of March, however it would actually end up lasting much longer, continuing throughout the summer. The information given to the public at the time was that the disease was highly contagious and the best source of action was to remain home in an effort to prevent the spread. This resulted in me, a 19 year old physics student who had just completed his first year at university with a lot of free time that was originally set aside for summer leisure. This circumstance led to the idea of undertaking a coding project that would consume some of my time.

I think it's important to mention just how limited my experience with coding has been in the past, before creating this website my only other interactions with writing code was, a game design course I took when I was 11 or 12 years of age, an arduino board I programmed to do simple tasks like making a beeping noise at different intervals or flashing its LED at varying frequencies and the Introduction to Programming module I had just completed in the semester before summer began which I admittedly did do quite well in. My experience in relation to HTML specifically has been limited to Notepad files on my desktop which I would then save has .html files. Not exactly the most promising background for someone planning to write their entire website from scratch, connect it to a purchased domain and then host it themselves online using a raspberry pi for people to be able to access publicly, however I did have 1) A lot of free time 2) Lots of publicly available tutorials and forms where previous website novices had already asked similar questions and 3) some friends who were far more adapt at HTML, CSS and Javascript than I will ever be.

My website initially was just a basic template I had created by following along a youtube tutorial which created the basics of a webpage, such as the header, the navigation bar, the body and the footer. Once I was finished with the tutorial I attempted to add my own personal touches to the website, including a popup window that showed up as soon as you reached the website that had my face on it, as well as 4 basic panels that linked you to the raspberry pi hosting guide I followed, a library which had some basic pictures of books I had read, my CV and then a page with a link to each of my lab reports I had written in year 1. All of these panels still exist in one form or another today on my current website.




                            [Original home page and library]                           VS                           [Current home page and library]

Once I had actual code that somewhat represented a website, it was time to invest actual money into it. Technically I could have done this entire project without spending anything, although there would be a few drawbacks. One of the first things I purchased for my website was the domain, I bought the domain jamiesomers.ie using register365 for exactly €6.04, I could have spent more if I wanted them to host my website for me, and I could have got a free domain if I was willing to give up some of the customization, domains ending in .tk .ml or some other uncommon variant are usually free. In the end I opted to go for a domain that will cost me roughly €30/year to retain and instead of paying a monthly fee to have them also host my website I would recuperate some of the cost by making a one time purchase on a raspberry pi which I could keep in my home and would host my website to the internet until it inevitably dies. I decided to go with the latest raspberry pi model as it was the most powerful and I wasn't sure whether or not it could handle pushing this much content to whoever happens to stumble across my website. I ordered a Raspberry Pi 4 Model B starter kit with 8GB of ram which ended up costing me €112 including delivery, this means the raspberry pi would have to run for 21 months in order to pay for itself in hosting costs (€5.39 p/m) at which point any extra life span would go towards paying off the yearly domain cost.

I had never even held a raspberry pi before, so I was surprised when using it to host a website with apache2 was so easy that I had my website up and running in about 3 hours. All I really did was follow the raspberry pi official guide to hosting using apache 2 and then transfered my website code over to the SD card in the raspberry pi using a USB drive. Raspbian is the operating system uniquely designed for raspberry pi's and it was relatively easy to use, the biggest issue I ran into was that by default a new user doesn't have permission to edit any of the files found on the machine, so you have to use the command prompt to give yourself permissions every time you find a folder you need editing rights to. Currently my website sits at over 2,000 lines of code, 1,200 of which belongs to the style.css file and due to my novice nature some of which is obsolete code that I may have forgot to delete when testing certain types of code.

There are certain things I would like to add to the website in the future, including better support for mobile viewing, however as I am returning to year 2 of my degree soon I am comfortable leaving the website in its current state and I am satisfied that it has at least somewhat improved my ability to code in general, as well as taught me specific skills when using HTML, CSS and Javascript.