/ Hosting

Setting up a Ghost blog for free

Setting up a blog, in general, is about two things.
  1. Hosting Space - A place where your Content Management System(CMS) resides.
  2. Domain Name - something like www.foo.com which points to the hosting space. So whenever someone hits the domain name in the browser, the CMS gives the response in return.

Now that you know the basics, also know that setting up a blog has never been easier. A lot of hosting companies these days, let you install a Content Management Systems(CMS) just by the click of a button. But the limiting part is, that they only offer CMSs that are PHP-based and are popular like Wordpress, Joomla, Drupal, etc. The older and popular a CMS gets, the corresponding support, the number of plugins and easiness to install increases.
If you want one of these PHP-based CMSs, it's pretty straight forward. Without getting distracted from our end goal of setting up a ghost blog, let us quickly explore how to setup a Wordpress blog, so that we know it's a cake walk.

Setting up a Wordpress blog for free

  1. Get a free domain name at Dot TK. For the time being, forward the domain to http://www.google.com.
  2. For hosting, head over to Hostinger. Firstly Signup and then under hosting, select New Hosting Account. Now select the free option.
  3. In the setup, select the domain name you got from Dot TK.
  4. Under Account > Details, note the IP for the 'A' DNS record and update the same in your domain name at Dot TK.
  5. Again at Hostinger, go to Website > Auto Installer > Wordpress > Install.

The DNS update would take around 24 hours after which you'll have your Wordpress blog ready at the domain name you got from Dot TK.

If that's so easy and everybody is doing it..

Why Ghost at all?

  • Ghost is all about minimalism. With the plethora of plugins and features that Wordpress offers, one might get lost and loses track of what matters the most - the content. With Ghost, you write in Markdown so you don't have to worry about the aesthetics. It'll be beautiful.
  • Since it is built on top of NodeJS, it is blazing fast.
  • It has SEO and Social-Sharing built-in. Along with the traditional SEO features like readable URL structures, Facebook open graph objects, sitemaps, etc., it has Accelerated Mobile Pages( AMP ) too!

Without any more delay, let's get started with Ghost.

Setting up a Ghost blog - The minimalist way

  1. For hosting, we'll be using Redhat Openshift. Openshift has cartridges, which are a set of web frameworks, databases, monitoring services or connectors. Together they help run an application. Openshift already has a Ghost Cartridge, so post signup, all you have to do is open this cartridge link and click deploy. It'll directly land you on the create application page and you just have to click 'Create Application'.

There you go!
You have a functioning Ghost blog available at a public URL: [application-name]-[username].rhcloud.com eg. nodejs-foo.rhcloud.com which serves both HTTP and HTTPS requests!

Setting up the Ghost blog - The complete way

Hook up a custom domain name

  1. Repeat Step 1 from the setting up a Wordpress blog to get your domain name.
  2. Openshift works on CNAME records and not all domain registrars support setting your base hostname( eg. testdomainname.gq ) as a CNAME so we'll have to use a third party who would do the routing for us. And this would be Cloudflare. So signup and add your domain name from step 1.
  3. At Cloudflare, go to DNS and create two CNAME records with name and values as -
    1. name: [yourdomain], value: [openshift public URL] ( eg. name: testdomainname.gq, value: ghost-foo.rhcloud.com )
    2. name: www, value: [yourdomain] ( eg. name: www, value: testdomainname.gq )
  4. Go back to your domain registrar( Dot TK in this case ) and update the name servers from those that you get from Cloudflare.
  5. Go to your Openshift web console and open the ghost application. Change alias of the application to the domain name from step 1.
  6. Also in the application page, copy the git repository URL and clone it locally.
  7. In this locally cloned project, open config.js present at the root, change the url property in every production property to your custom domain name with the HTTP protocol. eg. http://www.foo.com
  8. Stage this change, commit and push. The push automatically triggers deployment.

Since there are DNS and Nameserver updates involved, it might take around 24-48 hours for your domain to point to your Cloudflare and for Cloudflare to point to your Openshift server.

Redirect HTTP requests to HTTPS

In the cloud (server), usually, an HTTPS request received from a client is forwarded to other services as an HTTP, post validity and authentication. Other services detect the original request's protocol based on a header( X-Forwarded-Proto ) set by the endpoint service. So in our case, the HTTPS request first received by Cloudflare is forwarded as HTTP to our Openshift server and then again as HTTP to our Ghost application. We let Cloudflare handle the request redirection for HTTP to HTTPS requests while our Openshift server and application continue to serve for HTTP requests. This can be done by adding the following Page Rules in Cloudflare.

Page Rules in Cloudflare
  1. URL match string: http://testdomain.gq/*
    Setting Value 1: Forwarding URL
    Setting Value 2: 301 - Permanent redirect
    Setting Value 3: http://www.testdomain.gq/$1
    What does it do? - redirect HTTP non-www versions of the URL to the HTTP www version

  2. URL match string: https://testdomain.gq/*
    Setting Value 1: Forwarding URL
    Setting Value 2: 301 - Permanent redirect
    Setting Value 3: https://www.testdomain.gq/$1
    What does it do? - redirect non-www HTTPS versions of the URL to the HTTPS www version

  3. URL match string: http://www.testdomain.gq/*
    Setting Value 1: Always Use HTTPS
    What does it do? - redirect HTTP www versions of the URL to the HTTPS www version.

These 3 rules handle all your HTTP and HTTPS requests to be redirected to their HTTPS www versions.

Tip

  • Install the Openshift Command Line Interface(CLI) locally by issuing commands gem install rhc and rhc setup for an easy restart and tailing logs of the application.

Note: Since we're setting this up for free, there are a few extra steps involved that you wouldn't have to follow if you were paying. But this is a great way of learning and starting for free.

Umang Ganvir

Umang Ganvir

Techie. Javascript Evangelist. Passionate Learner. Talks about Motivation and Value Creation.

Read More