Ghost 0.11.x on a PI 3.

Raspberry PI as a server?

Yes I decided to re-purpose my raspberry PI 3 from the now dormant CNC project to it being a low power server. The WIFI bridge I run at home between my main router and my servers is becoming a pain to manage with 2.4GHZ being so saturated that my blog keeps fading in and out. The solution could have been an old netbook with linux installed on it, but honestly I do not need something so power hungry. (I cant believe I am calling a netbook power hungry), the difference between the netbook with a single core atom and my quad core pi is probably around 3-10x the power consumption weighing heavily against the netbook.

The setup.

I downloaded a lite version of Raspbian. Specifically RASPBIAN JESSIE LITE and went ahead and configured it while it is pluged in on my secondary monitor. The configuration is simple. The command is raspi-config

Before installing the following steps will be taken to prepare the server

  • Set a strong password.
  • Set a new hostname (optional)
  • Enable SSH
  • Change SSH port to something else. I am doing this even though this server sits behind a firewall.
  • Dumb down video to 16MB, as this thing does not have a monitor, nor does it have a gui.
  • Place PI near router, plug in a phone charger from my old LG phone with a short cable and short Ethernet cable to keep things from getting out of hand.
  • Set the keyboard type
  • Set Timezone
  • Set country
  • Finally Velcro the pi to the wall and connect Ethernet and power.

Protecting the PI.

I am not going to just place a bare computer on the wall, the router however resides in a closet with clothes in it. To protect it from heat as well as some abuse I picked up a raspberry pi case. In this case I did not 3d print one as the case came with screws and heat-sinks for the pricey sum of $6, coincidentally that is nearly the price of the heat-sinks alone. The quality of the case is outstanding and it secures the pi two fold, once by clipping in and secondly with small screws. No hassle. This is the case

Here is what it looks like with the PI 3 in it.

Ghost Setup

As I am writing this on my old server and will be migrating the content to the new server once it is complete and I had enough of a chance to kick the tires. The makes of ghost blog recommends installing Node v4 LTS, this is however a crap shoot and does not function properly on the raspberry pi. I recommend node 6.9, the problems with node 4 LTS on a raspberry pi are numerous, including not functioning at all, not compiling, not being able to compile node-sqlite etc etc, I scratched my head quite a bit. I used this guide as a starting point with much more research than what that blog provides, several hours later and many edits to this blog post I finally got it running. The draft for this post served as a notepad in the mean time.

Enough babbling. Here is the crash course.

Upgrading the PI first

  • sudo apt-get update && sudo apt-get dist-upgrade

Installing NODEjs

  • sudo curl -sL | sudo bash -
  • sudo apt-get install -y build-essential python-dev nodejs
  • node -v (v6.9.2 as of this writing)
  • npm -v (3.10.9 as of this writing)

Install sqlite3

  • sudo apt-get install sqlite3
  • sudo apt-get install sqlite

Installing GHOST Blog

  • sudo mkdir -p /var/www/
  • cd /var/www/
  • sudo wget
  • sudo unzip -d ghost
  • cd ghost/
  • sudo npm install sqlite3 --unsafe-perm
  • sudo npm install --production
  • sudo cp config.example.js config.js
  • sudo npm start --production

Install NGINX

I am installing NGINX instead of Apache as a proxy. Mainly because its easy. But you may chose to do an Apache v3 install or whatever you wish at this point. Below are the commands and the code for the proxy to work.

  • sudo apt-get install nginx
  • cd /etc/nginx/
  • sudo rm sites-enabled/default
  • sudo touch /etc/nginx/sites-available/ghost
  • sudo vi /etc/nginx/sites-available/ghost (enter below code in blank file)

server { listen 80; server_name your_domain.tld; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass; } }

  • sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost

Security We should add a user that does not necessarily have sudo access to the rest of the machine in case the blog is compromised. The below steps show you how to do that as well.

  • sudo adduser --shell /bin/bash --gecos 'Ghost application' ghost
  • sudo chown -R ghost:ghost /var/www/ghost/

Ghost blog auto start

  • sudo npm install -g forever NOTE: this may take a bit of time
  • sudo su - ghost
  • forever start index.js
  • NODE_ENV=production forever start index.js

Importing the blog to the new server First things first is we should export our old blog first.

The steps as always

  • Login to your old ghost blog
  • Click on the "Labs" tab
  • Click on export

You may have noticed that the json file is quite small. In fact it is only the text from your blog. It does not include the images from it. To export the images, follow the below steps.

  • ssh into your old blog
  • cd /var/www/nodejs/ghost/content/ Note: this is a sample directory yours blog root may be somewhere else.
  • tar -cvf images.tar images
  • scp -p images.tar user@newblog:/tmp NOTE: put in your own user/hostname, otherwise you may need to use winscp and pick those files up.
  • cd /directory/where/backup/images/are
  • tar -xvf images.tar
  • chown -R ghost:ghost images/ NOTE: Providing that ghost is the user name you are using for ghost forever run.
  • cd images
  • cp -pR * /var/www/ghost/content/images/

Now its time to import the json file we exported earlier.

  • Login to your new ghost blog EX
  • click on Labs
  • click on import content

The only content now not available is the user profile picture as well as the blog banner. You will find both of those in the images sub directories.

That is it, your done migrating. Hopefully this blog post will come in handy to some people. I still have to tweak this server now, and I want to add my analytics reporting etc etc. This has been a long day fussing around with ghost. :)

Until next time, ciao

Bruno M.

Engineer, Tinkerer, Technologist, Maker.

New York

Subscribe to engineerd3d

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!