Ghost on Ubuntu

Ghost is a free open source blogging platform built with Node.js. It started as a Kickstarter project and turned into a great blogging platform that is still under active development.

It can be self hosted or you can choose a hosted built at Ghost.org.

It uses Sqlite by default as it’s Database, you use MySQL to.

Its easy to setup and maintain Ghost compared to other blogging platforms and CMS, self hosting gives you the freedom to choose your own server.

If you don’t already have a server or planning to host it on a Ubuntu VPS, I would personally recommend Digital Ocean, Ghost.org is also hosted on it.

Getting started

Installing dependencies required for running Ghost into production.

Installing Node.js

Adding the Node.js repository to get the latest stable version of Node.js (requires: cURL).

curl -sL https://deb.nodesource.com/setup | sudo bash -  

Installing Node.js

sudo apt-get install nodejs # NPM comes with it.  

Adding NGINX stable repository to get latest version of NGINX.

sudo apt add-repository ppa:nginx/stable  

Installing NGINX.

sudo apt-get update && sudo apt-get install nginx-full  

Installing Sqlite.

sudo apt-get install sqlite3  

Installing Supervisor, for handling Ghost at startup and crash or restart.

sudo apt-get install supervisor  

Downloading Ghost stable zip.

wget https://ghost.org/zip/ghost-latest.zip  

cURL users can get it to.

curl -# -L -O http://ghost.org/zip/ghost-latest.zip  

Unzipping Ghost zip file that we downloaded.

unzip ghost-latest.zip -d Ghost  

Turn Ghost directory into current directory.

cd Ghost/  

Installing production dependencies for Ghost using NPM.

npm install --production  

Test run to see, to see if everything is running fine:

npm start --production  

If you don’t get any errors, you are good to go ahead.

Adding Ghost service configuration to Supervisor, by creating a new ghost.conf file.

sudo nano /etc/supervisor/conf.d/ghost.conf  

Add the lines below, edited it to match you system settings, you can it under a separate user for Ghost, don’t run it under the root user.

[program:ghost]  
command = npm start --production  
directory = /path/to/ghost # Change to the place you have stored Ghost  
user = ghost # Change the username Ghost will be running under  
autostart = true  
autorestart = true  
stdout_logfile = /var/log/supervisor/ghost.log  
stderr_logfile = /var/log/supervisor/ghost_err.log  
environment = NODE_ENV="production"  

Save file CTRL + X + Y and hit ENTER.

Ghost stores all it’s configuration in a config.js file, which need to be created by coping the config.example.js file to config.js.

cp config.example.js config.js  

Edit the file to your preference, don’t forget to edit the url: string to your domain.

Starting Ghost as a Supervisor service.

sudo supervisorctl start ghost  

Now Ghost will be running on port 2368.

Reverse proxying it using NGINX to run it on port 80.

Edit the default nginx configuration.

sudo nano /etc/nginx/sites-enabled/default  

Add the following to the default file.

server {  
        listen 80; 
        server_name yourdomain.com; # Change this to your domain

        location / {
        proxy_pass       http://127.0.0.1:2368;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;
        }

    }

Restart NGINX.

sudo service nginx restart  

Visit your domain, you will now be greeted by Ghost setup page, fill the required information, now you have Ghost setup.

Happy Blogging.

Thanks for reading, have a question? leave a comment below.

Leave a Reply