Yudi Rahono
Rahono
Published in
4 min readFeb 1, 2016

--

Deploy Ghost with Dokku on Digitalocean (plus Letsencrypt)

Choosing publishing platform might not be an easy task for some people including me, I have used Wordpress as my publishing platform but not for my personal blog tho. For example, like this website I have been deployed several years ago with Wordpress platform but it’s hard to focus on content since it has too many navigations and plugins. So I chose to use ghost with dokku on Digitalocean stack heres why:

  • Ghost is much more simpler.
  • Dokku? I was planning to use ghost with multiple domains with a single installation but not like WordPress that supports multiple domains with wpmu, it needs to deploy instances per domain and the simplest way is to use dokku and dokku on DO is only a click away to deploy droplet.
  • Updating ghost with sync and push on git.
  • Letsencrypt? just want to test and use free and bleeding edge open source certificate :p, before I use comodo SSL for this domain.

Versions

Ubuntu 14.04
Dokku v0.4.12
Ghost 0.7.5
dokku-letsencrypt 0.6.0

Spawn Dokku on Digitalocean

Deploy dokku with Digitalocean one-click app dokku droplet.

1. Selecting Dokku Images

You will need to choose several options according to your needs and I just realized that Digitalocean also have ghost one click app, but its need separate install and manually configure nginx for each installation.

2. Configuring Dokku Host

After droplet created you can browse your droplet IP address and you will see the configuration.

  • Admin Access. if you use Digitalocean public key this field will be filled with your Digitialocean public key
  • Hostname Enter your desired domain name to use it with dokku containers
  • Use Virtualhost naming if you want to deploy each dokku container on your hostname subdomain

After all necessary field has been filled you can click the finish setup button and deploy your apps to dokku.

Creating Dokku Apps

Dokku has a command line administrative interface you can list all available command by ssh (ssh dokku@your-host.name) to your host with dokku username.

By running apps:create command it will create your container and git endpoint, for example to create playground app you will need to run
ssh dokku@your-host.name apps:create playground and it will create git bare repository and it should look like ssh://dokku@your-host.name:playground. You can read more about dokku here. You can also add your desired domain name to your container.

$ ssh dokku@host.name apps:create playground $ ssh dokku@host.name domains:add playground playground.rahono.xyz

Deploy Ghost

1. Download Ghost Release
You can download latest ghost release on their download page and extract it to your desired folder and copy config.example.js file to config.js.

$ wget https://ghost.org/zip/ghost-0.7.5.zip $ unzip -d playground ghost-0.7.5.zip $ cd playground $ cp config.example.js config.js

2. Configure Ghost
For production environment, you need to configure valid mail transport and change the host (production.server.host) configuration to '0.0.0.0' and the port to process.env.PORT this will use custom port assigned to your ghost container, your config file should look like.

// config.js config = { // ... production: { url: 'http://playground.rahono.xyz', mail: { transport: 'SMTP', options: { service: 'Mailgun', auth: { user: process.env.MAILGUN_USERNAME, pass: process.env.MAILGUN_PASSWORD } } }, database: { client: 'sqlite3', connection: { filename: path.join(__dirname, '/content/data/ghost.db') }, debug: false }, server: { host: '0.0.0.0', port: process.env.PORT } } // ... }

I still use sqlite because according to Sqlite it still able to serve small to medium website and I was use low memory deployment so I prefer to not use full fledged SQL server.

3. Deploy Your Ghost
Your ghost application folder needs to be git repository to be able to deploy to dokku and exclude generated folders by npm and bower to your git, add necessary file to your git and push it to your dokku remote.

$ git init $ echo 'node_modules' > .gitignore $ git remote add dokku dokku@host.name:playground $ git add . $ git commit -am "Initial Commit" $ git push dokku master

after the deploy command finish, you should be able to visit one of your domains linked to your dokku container.

$ ssh dokku@host.name domains playground playground.host.name playground.rahono.xyz

P.S if you got an error and you have small memory droplets it might be caused by out of memory error. you can add swap to your vm by following this guide.

Using Letsencrypt SSL Certificate

1. Install dokku-letsencrypt plugin
Installing plugin need root access to your dokku vm so you need to login to your vm with sudo or root access and install dokku-letencrypt plugin.

$ ssh root@host.name #> dokku plugin:install https://github.com/dokku/dokku-letsencrypt letsencrypt

2. Generate Certificate for your hosts
Generating SSL letsencrypt ssl certificate to your host, simply run plugin command for your app and it will automatically generating CSR and sign your certificate. but you need to add your email to letsencrypt app plugin

$ ssh dokku@host.name letsencrypt:email playground your@email.tld $ ssh dokku@host.name letsencrypt playground

Whats Next?

If you want to customize your casper theme you can read more on ghost guid here and theme are located under content/theme inside your the ghost directory.

You can signup to Digitalocean by using this link and get free 10$ credit upon signup.

Originally published at rahono.com on February 1, 2016.

--

--