Creating laurencepike.com

Hello world.

Welcome to my website.

The first thing I want to write about is how I created this website, it’s not very complicated, but a quite fun little project that took a day or two.

Old Raspberry Pi 2 that’s been gathering dust since 2015

This site is running off of a Raspberry Pi 2 I had lying around from years ago, it’s plugged into ethernet and power, and haphazardly tossed behind a bookshelf in the corner of my office. It’s not connected to any monitors, although during setup I did plug it into a TV and connected a mouse and keyboard – but after initial set up I can update the blog from any location by using the websites admin page, and I can check the status of the server and run updates either through ssh or VPC using nomachine.

The site’s critical server haphazardly tossed amongst a bundle of wires

Hardware

My Raspberry Pi 2 was already installed in the case from a project I did back in 2015. It was very easy to install, it’s just a matter of clipping it in. I no longer had a microSD card for the Raspberry Pi 2, so I purchased one for ¥880 (aprx. $8USD) from Amazon.

Configuring the Raspberry Pi

First thing that was necessary was to get the latest available version of Raspbian for my Raspberry Pi 2 and flash it to the microSD card. Fortunately this is very simple to do, I used the operating systems download page and chose the option available labeled as Raspberry Pi OS with desktop. I then used balenaEtcher to flash the microSD with the Raspberry Pi OS.

Once complete I put the microSD card into the Raspberry Pi 2. I connected the Raspberry Pi to my television and added a keyboard and mouse and powered on.

I followed the onscreen setup for Raspberry Pi OS, choosing location and language, but leaving all other options as default. I then enabled SSH in the Raspberry Pi Configuration application. I installed nomachine using the guide at their website for raspberry pi installation. Once these steps were complete I could remove the tv connection as well as the mouse and keyboard, all the rest of the steps could be done via my main windows computer by remotely connecting the Raspberry Pi. (If you don’t want to remote connect though all the remaining tasks can also be done on the Raspberry Pi)

If you’re attempting to do this as well, make sure to note the IP address of your Raspberry Pi by running the following command in terminal (prior to unconnected everything)

hostname -I

Setting up WordPress server

From my Windows machine I opened up Windows Terminal and ssh’d into my Raspberry Pi.

I found this fantastic article about how to set up a WordPress server on a Raspberry Pi, which I basically followed to a tee. I had two issues, one was that mysql isn’t available on Raspberry Pi OS by default, so I went with mariadb using the command below.

sudo apt install mariadb-server php-mysql -y

MariaDB works identically to mysql and even uses the same mysql commands to operate, it’s a complete drop-in replacement.

The other issue I had was that WordPress was unable to connect to the database with the credentials provided by the article. I tried using a different mysql user, and created user “wordy”. Either I had a typo somewhere before, or root user didn’t work for some reason. Either way I decided wordy was a fitting name for this PC. I updated the Raspberry Pi Configuration with the hostname Wordy as well, now it will show up as Wordy on my local network.

With all that set up I could then connect to the wordpress server locally using the IP in my web browser. This allows me to configure the server and add content.

Image Hosting

I plan to show photos I’ve taken around Japan on this website, and their file sizes and the storage space and speed of the little Raspberry Pi 2 are limited. For this reason I decided to host the images using a hosting service, at this time I’ve gone with AWS S3 Buckets, however I will be looking for alternatives that make it easier to host responsive images as raw S3 management is cumbersome.

Getting the Domain

I had held laurencepike.com many years prior but didn’t have a need for it, and so I let my ownership expire. Luckily when I decided I’d like to work on this project, it was available. I used Google Domains to purchase the domain for ¥1440/yr (aprx. $14USD). There were some cheaper options, but I use Google services a lot, and so it felt easier to just go with them.

Linking Wordy to the World Wide Web

Just completed this shortly by the 24 hour mark.. it was by far the hardest step with several of hours of debugging.

One of the ways people connect internal devices to the web is to get a static IP for their router and then use port forwarding. This unfortunately was not an option for me as I soon realized my apartment complex used one router which was controlled by the ISP. This meant that port forwarding was not an option.

I’ve worked with port forwarding before, but without being able to use it, I honestly didn’t know if this was even possible. I scoured the web looking for stackoverflow articles and how-to that might shed some light. Eventually I came upon this helpful stackoverflow exchange. At first I was elated that I’d came across the solution – ssh reverse tunnels. They sounded cool so I was sure I’d have my local site available to the world in no time.

With ssh reverse tunnels you need a server that is accessible via the web. Your local computer (Wordy) then ssh’s into that web accessible server, but while doing that specifies that the web accessible server should forward any traffic it receives to XYZ port to ABC port on the local computer (Wordy). Well, that sounded straight enough to me, I’d just create an AWS EC2 instance on free tier, use it as the web accessible server, and ssh into and reverse to ports to my Raspberry Pi Wordy. It was a little annoying to be using EC2 after going all the way to build the server on a Raspberry Pi, but at least I could use the free tier and I’d still be having all my website logic physically at home.

However it wasn’t so simple.

I’m going to fast forward past A LOT of headaches and debugging, and skip straight to what made it work.

  • Configured Google Domains DNS settings to go to my EC2 instance IP address for both www.laurencepike.com & laurencepike.com
  • Allowed access to HTTP requests from all IPs to EC2 instance
  • Allowed root access on EC2 instance
  • Configured EC2 instance to allow gateway and forward tcp connections
  • Set ~/.ssh/config on Wordy as follows:
Host ec2frontend
    HostName www.laurencepike.com
    User root
    Port 22
    IdentityFile supersecret.pem
    TCPKeepAlive no
    ServerAliveInterval 15
    ServerAliveCountMax 3
    RemoteForward 80 localhost:80
    DynamicForward 8108
  • Run autossh on Wordy as follows:
autossh -M 0 -Nf ec2frontend

And that’s it. The site is now live on laurencepike.com, I can create and edit posts. It took just under 24 hours from start to end, although most of that time was spent sleeping or doing my day job. Roughly it was two nights spending about 4 hours tinkering.

Cost of laurencepike.com

Going into this project I didn’t want to spend much, I just mainly wanted to see what was possible with existing hardware I had.

The Raspberry Pi 2 was just laying around, it was literally sitting in a drawer for the past 6 years. The price of a Raspberry Pi 2 with the case I have can be found on ebay for about $45. I feel though that this price is inflated compared to what it’s worth by it’s nostalgia qualities. You can pick up a brand new Raspberry Pi 4B for $35 (albeit not with a case, but it’s much much faster)!

I did though need to buy a microSD card, and pay for the domain.

The total upfront cost was: ¥2280 (~$20USD)
Recurring costs will be: ¥1400/yr (~$12USD)

Final Thoughts

I enjoyed this project, I’m happy that I was able to bring life back to the Raspberry Pi 2. It was a bit of a learning experience in networking. I learned about ssh reverse tunneling and think it’s pretty neat, though I’m not sure how well it will hold up with restarting the server or eating into the EC2 free tier data cap.

I think with access to the router and being able to assign a static IP and access port forwarding, a Raspberry Pi makes for a great server for a simple WordPress site that you expect minimal traffic to. However without access to port forwarding the reliance on EC2 instances makes the usage of a Raspberry Pi more cumbersome. Why run the Raspberry Pi at all when I could just host it all on EC2 if I’ve got to run an EC2 instance anyway?

For me though at this point I’m still keen on keeping this website running on ol’ Wordy here. If anything just to say I did it. It might not be the most elegant solution, but it’s the one the one I set out to achieve, and for that I’m happy.

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.