Cutting Costs: Migrating CMS to a Raspberry Pi
This is Part I of my journey. To view Part 2, click here.
Recently, I received a notice from my Content Management System (CMS) hosting provider, alerting me of my subscription’s expiration and advising me to verify the status of my billing methods. Considering the prevailing trend among tech companies to prioritize cost reduction, I’ve been inspired to follow suit. I’ve embarked on an analysis of my expenses, particularly focusing on my website, and I’m determined to implement strategic cost-cutting measures moving forward.
The Outgoing Setup
For the past two years, my website has operated with a headless frontend hosted on Netlify and a CMS backend hosted on Flywheel. This configuration has served me well, especially given Flywheel’s toolset for local development, and having the ease of accessing my CMS from anywhere in the world to make updates to my website. With the ability to run my CMS locally and seamlessly deploy changes to staging or production environments, Flywheel has been a great asset. Additionally, the constant backups and proactive email updates about my website’s status have provided peace of mind, ensuring it remains responsive and accessible to the frontend.
However, as I reflect on the past two years, I’ve realized that my website’s update frequency has decreased significantly, and the traffic it generates doesn’t justify the ongoing expense of this hosting setup. While these services were essential for content updates and frontend build processes with Next.js Static Site Generation, recent optimizations I made, such as configuring Next.js to download images during the build process, have made certain features redundant. As a result, I’ve decided to reevaluate my hosting needs and streamline my expenses accordingly.
The New Setup
The new setup had to resemble the old setup; my requirements were:
- Low cost or free.
- Being able to easily manage content through a CMS.
- Be able to backup content.
- Have GraphQL endpoints for content.
Initial Research
Initially, I contemplated switching to another CMS host that offered more budget-friendly or even free options. However, most alternatives I explored either added advertisements or incurred hidden costs. Just when I thought I hit a dead end, I stumbled upon an article detailing the process of migrating a WordPress site to Docker.
This revelation ignited a spark of curiosity within me. I already had a Raspberry Pi configured with Ubuntu Server, equipped with an M.2 drive, and encased in the Argon One case. My vision extended beyond merely hosting my website; I aimed to maximize the potential of this Raspberry Pi by leveraging it for various personal projects.
With determination and ambition, I embarked on the journey of migrating my WordPress CMS to my Raspberry Pi, using Docker Compose.
The Migration
After going through the WordPress and Docker documentation, community threads, and consulting Codeium, I began following a similar approach to this YouTube tutorial. Some hosting providers help you migrate your site to their servers for “free”, after signing up to one of their plans. However, because my goal is to cut costs, I had to migrate the website manually, and save a few dollars.
The first set of steps were quick and easy. Extracting the database took a few clicks, and thanks to Flywheel’s assistance, I effortlessly pulled my entire CMS locally to extract its content.
The second set of steps required some networking and Docker knowledge. Since I wanted to host my CMS on my Raspberry Pi, I had to transfer those files via SSH from my computer to my Raspberry Pi on my local network. Upon attempting to launch my CMS for the first time, I encountered a hurdle: connection failures to the database, due to mismatched database prefixes and credentials.
The final set of steps required a few SQL commands. Upon gaining access to my CMS locally, I noticed discrepancies between the database and file tree. After thorough troubleshooting, I pinpointed the need to update certain values reflecting the old CMS URL to the new one. With these adjustments in place, the familiar landscape of my CMS, reminiscent of its Flywheel days, emerged once again.
Connecting the Frontend to My Local CMS
Using ngrok tunnels allow developers to securely expose projects running locally to the internet under a new URL. Configuring ngrok was a necessary step to allow the frontend to communicate with my CMS running locally.
The strategic deployment of ngrok tunnels revolves around a carefully choreographed workflow: activating the tunnel post-CMS updates to allow ample time for the frontend to compile the static site. Upon completion of the build process, I promptly deactivated the tunnel, safeguarding my CMS from internet crawlers and fortifying its security measures.
What about Backups?
Backups are necessary for any application that wants redundancy. It provides a snapshot of your content or data and saves it to memory. These backups can then be used should something crucial happen to any environment.
To solve this, I am currently manually extracting my database and CMS content, zipping them, and saving it on a USB. These backups provide a checkpoint to the latest content available in my CMS. In the case that my Raspberry Pi gets fried, or I am unable to access my data, I can grab my latest backup and run it on a new Docker container, getting everything I could have potentially lost, back.
To read more about backups, read part 2 of my journey here.
Conclusion
In conclusion, the journey of migrating my Content Management System (CMS) to a Raspberry Pi has been a strategic endeavor aimed at reducing costs while maintaining functionality and security. Reflecting on the past hosting setup, which relied on services from Flywheel, it became evident that the expenses outweighed the benefits. The transition involved extensive research, manual migration processes, and the adoption of tools like Docker and ngrok tunnels to ensure seamless operation and enhanced security. With backups now managed manually, this new setup promises not only cost savings but also increased control and adaptability, epitomizing the fusion of pragmatism and innovation in the pursuit of efficient website management.