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 its Database, you use MySQL to.

It’s 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 an 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 –Code language: JavaScript (javascript)

Installing Node.js

sudo apt-get install nodejsCode language: JavaScript (javascript)

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-fullCode language: JavaScript (javascript)

Installing SQLite.

sudo apt-get install sqlite3Code language: JavaScript (javascript)

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

sudo apt-get install supervisorCode language: JavaScript (javascript)

Downloading Ghost stable zip.

wget https://ghost.org/zip/ghost-latest.zipCode language: JavaScript (javascript)

cURL users can get it to.

curl -# -L -O http://ghost.org/zip/ghost-latest.zipCode language: PHP (php)

Unzipping Ghost zip file that we downloaded.

unzip ghost-latest.zip -d GhostCode language: CSS (css)

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 your 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"

Code language: TOML, also INI (ini)

Save file CTRL + X + Y and hit ENTER.

Ghost stores all its 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.jsCode language: CSS (css)

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/defaultCode language: JavaScript (javascript)

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;
	}
}

Code language: Nginx (nginx)

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.