I have decided to write a post to show how to create your own personal blog in just a few steps, and how to host it in a Raspberry Pi.
Why running a blog on your own?
The first thing that came in my mind when thinking about creating a tech blog was:
"Why should I create my own platform instead of using a ready-to-use ecosystem like Wordpress or Wix?"
Which are by the way great solutions available to everyone for "free".
I spent some time wandering, and then I had the idea of bringing back to live my old Raspberry Pi and making something fun with it. Because those ecosystems mentioned above usually will charge you a few dollars a month to host your blog, it is cool to have your own server so you can save some money at the end of the day.
However, when we decide to do everything by ourselves, things can go wrong in a blink of an eye. So, be warned that this tutorial is meant to be for educational purposes only. Just bear in mind the implementation here presented is not reliable for a production environment.
The components and skills we'll need to complete this tutorial are quite simple. We'll need:
- A Raspberry Pi Model B2
- A computer
- An Internet Routing with dedicated Internet link (IP address)
- An ethernet network cable or USB wifi adapter for the Raspberry Pi
Make sure you are running the latest version of the Debian OS in your Raspberry Pi. I installed in mine the version 3.2.0. If you aren't sure about your version, we can check it using the following command:
pi@raspberrypi:~/Documents/git/local $ cat /etc/os-release PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" NAME="Raspbian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)"
Ghost blog platform
Ghost is an amazing open-source blog platform available on GitHub for anyone in need of his/her own ready-to-go blog. We'll install Ghost in the Raspberry Pi and set it as a web server so we can access it from outside of our local network.
Raspberry Pi setup
First of all, you'll need to have the Git installed in your Raspberry Pi. If you have the latest version of Debian OS, git will be pre-installed already. The setup I created in my network can be seen in the diagram below.
If you don't have your Raspberry Pi connected to an external monitor, you can access it using ssh connection from another computer. Just open any terminal of your choice, and make a ssh connection with the Raspberry Pi. Make sure both computers can communicate, in other words, they need to be in the same subnet.
We'll need to clone the Ghost repository in the Raspberry Pi. It is important that you update the Raspberry Pi repositories by typing:
$ sudo apt-get update
- Clone the git repository inside your Raspberry Pi.
$ sudo git clone https://github.com/TryGhost/Ghost
2. Update the node.js and nmp packages for the versions supported by Ghost. You can find it out on their website.
$ sudo npm install npm@latest -g
The versions of my Raspberry Pi is shown below.
If you encounter the error
info There appears to be trouble with your network connection. Retrying...
It is a sing that your nmp version is not compatible with the one required for Ghost. So, it is pivotal you have the versions shown above installed in your Raspberry Pi.
3. Now it is time to get things actually done. Install Ghost inside the directory you made the git checkout.
$ sudo npm install ghost-cli -g
4. After completion, you will need to create a folder to install Ghost locally. This folder needs to be empty and with the rights of reading and writing. In order to do so, create a directory.
$ sudo mkdir local
Now you have to exit superuser and give all permissions for this folder:
$ sudo chmod -R a+rwx local/
4. Finally, let's install Ghost inside the folder we have created.
$ ghost install local
After one hour or so you should encounter the success logging info for the Ghost installation.
5. Now, after installing the Ghost, we need to do some configuration in order to get it up and running in your Raspberry Pi. Inside the folder you installed the Ghost, you'll find a configuration file named config.development.json. This file is the one used to set up most of the environment variables that Ghost uses. You'll need to change the variable URL, PORT, and HOST depending on your configuration. In my case, my server will be exposed under the URL http://jaimedantas.ddns.net in the port 9002. And the host IP of my Raspberry is 192.168.15.20.
Keep in mind these values must be based on your internal network configuration. As an example, I set my Internet router to forward the port 9002 from my public IP to the port 9002 of my Raspberry Pi (192.168.15.20).
After performing all settings of your Ghost correctly, you should be able to access its webpage:
We saw that it is possible to run an entire blog environment inside a Raspberry Pi with just a couple of hours of work. From now on, I will update this post as well as create new posts using only my Raspberry Pi to host it. I kept it running 24/7 so far, and I didn't encounter any problem what so ever while running this blog on it until this present day.
I hope you find this post interesting and helpful.