Installing Ghost on a Raspberry Pi
This post is deprecated. Ghost 1.0 has significantly simplified Ghost installation on a Raspberry Pi. See later post for details
This page is indebted to
https://ghostpi.pro/install-and-run-ghost-on-a-raspberry-pi/
Before we start
Make sure your router is forwarding HTTP requests on port 80 to the ip-address you will be assigning to your Raspberry Pi and your DNS entries for your sub-domain are correctly accessing your router's external ip-address
Install Raspian Lite on the Raspberry Pi
I like to use Etcher to write SD cards.
Remount the SD card and create a blank file ssh
in the Boot partition
On the Main partition edit /etc/dhcpcd.conf - you may need to switch to Root to do this. Append the following lines:
interface eth0
static ip_address=192.168.1.10/24
static routers=192.168.1.254
static domain_name_servers=192.168.1.254
Where: ip_address is the ip_address you plan to use for your Ghost server, and routers/domain_name_servers are the IP address of your router.
Insert the SD card in the Raspberry Pi and boot
Update the Raspberry Pi
SSH into the Raspberry Pi at the address you used above with the user-id of pi
and password raspberry
sudo apt-get update && sudo apt-get upgrade
sudo raspi-config
- Change Pi Password
- Change Hostname
- Enable SSH
- Expand Memory
- set memory split to 16MB
Install nginx
sudo apt-get install nginx
Edit /etc/nginx/nginx.conf
- increase
server_names_has_bucket_size
to 64
necessary for ghost - add
client_max_box_size 2m;
(i the same section)
Some ghost themes are quite large and need this to be able to be uploaded
Restart nginx sudo service nginx restart
and browse to the IP address of the Raspberry Pi to confirm nginx is working OK
Install nodejs
Install version 6.9.5 which is the latest fully suppoprted version of node.js for ghost
wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-armv7l.tar.gz
sudo mv node-v6.9.5-linux-armv7l.tar.gz /opt
cd /opt
sudo tar -xzf node-v6.9.5-linux-armv7l.tar.gz
sudo mv node-v6.9.5-linux-armv7l nodejs
sudo rm node-v6.9.5-linux-armv7l.tar.gz
sudo ln -s /opt/nodejs/bin/node /usr/bin/node
sudo ln -s /opt/nodejs/bin/npm /usr/bin/npm
Verify the install with node -v
install ghost for your target subdirectory
I want to use a subdomain of 'travels'
cd ~
wget https://ghost.org/zip/ghost-latest.zip
sudo mkdir /var/www/travels
sudo chown -R pi:pi /var/www/
sudo unzip -d /var/www/travels ghost-latest.zip
cd /var/www/travels/
npm install --production
sudo chown -R pi:pi /var/www/
This takes some time - there may be an error message because there is no pre-built sqlite3 - this is not a problem, the build process will continue and compile sqlite3 from source
Basic ghost configuration
cd /var/www/travels/
cp config.example.js config.js
nano config.js
- In the Production section
- Change url: to the URL of your subdomain/domain
(e.g.url: travels.two-drifters.org.uk
) - Change the server/host: to your ip-address
(e.g.host: '192.168.1.10'
)
- Change url: to the URL of your subdomain/domain
- In the Development section
- Change the server/host: to your ip-address
(e.g.host: '192.168.1.10'
)
- Change the server/host: to your ip-address
Test the Production environment
npm start --production'
and navigate to port 2368 at your ip-address in a browser (e.g. http://192.168.1.10:2368
)
Similarly test the development environment - npm start --development
NOW - go back and edit config.js again and change both the host:
fields you just changed, back to their original value of 127.0.0.1
ready for integration with nginx
Add proxy for nginx
cd /etc/nginx/sites-available/
and create a new config file:
sudo nano travels.conf
The contests of the config file should be:
server {
listen 80;
server_name travels.two-drifters.co.uk;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
And link into sites-enabled:
sudo ln -s /etc/nginx/sites-available/travels.conf /etc/nginx/sites-enabled/travels.conf
Restart nginx - sudo service nginx restart
Start ghost for your subdomain
cd /var/www/travels
npm start --production
You should now be able to navigate to your site's URL and see ghost running.
Next - Deploying Ghost at start-up