Ghost is a blogging engine where you can build your own blog within seconds if you know the steps. That said the setup to do so was not simple or intuitive, and someone can ended up spending a lot of time and effort getting the blog up and running.

This article seek to fix that particular problem. In it, I will list everything you need to host your own Ghost blog on your own server space. To be frank, it's a lot of steps, but ultimately you will control your own site and learn a bit about how the Internet works and how server management is done.

Table of Contents:

  • Buy a Domain Name
  • Get Hosting Space
  • Create a droplet
  • Add Your Domain to DigitalOcean
  • Install Ghost
  • Secure a droplet
  • Redirect www to non-www
  • Useful enhancements
  • Conclusion

Buy a Domain Name

The number one priority is to buy your own domain. You cannot start a website if you don't have a domain name.

But what the heck is a domain name anyway?

It’s basically a string of recognizable words that, when typed in the browser, redirects the user to your server IP. A server IP looks like 139.59.141.110 which is hard to rememebr by hard.

Here's a list of where you can buy/research domains:

I use digital ocean so I had to insert the following details in my namecheap account:

Get Hosting Space

You can do this in one of two ways. If by some miracle you already have your own web server in a location you control, you can just use that. The vast majority of people, though, don't have web servers just lying around, and so they have to rent server space and time from a provider for a monthly fee.

There are a TON of hosting providers out there, including:

The one I use and recommend is DigitalOcean; they have a fantastic interface which help you set up your "droplet" (AKA your server)  The cheapest plan they have is $5/month, which is reasonable good for web hosting and most importantly it offers one-click “application” installation.

Create a droplet

Login to your Digital Ocean account, then click New Project button and then Create a Droplet, choose Marketplace and select Ghost, select standard as plan 5£/mo, enable backups, select a region close to your audience to reduce the latency and select a hostname. As in the picture below:

Then click Create and waiting for less than 1 minute, your droplet information (username and password) will be send to your email.

Add Your Domain to DigitalOcean

After the droplet has been created right click and press add a domain as in the picture below:

After creating an A record which will redirect the www.pp.com to the server IP it should look like this. (assumming ppo as your domain name).`

Install Ghost

Login to your host, if you used unix you can run on Terminal otherwise right-click on the droplet and click access console.Assuming 123.456.7.8 is your droplet ip run the follow command:

 ssh root@123.456.7.8

You’ll see welcome message and will aks you for password use the one that was emailed to you by Digital Ocean.

After logged in, System will force you to changing a password.$ Changing password for root.
$ (current) UNIX password:
$ Enter new UNIX password:
$ Retype new UNIX password:

Follow the steps and some point will ask you the domain name:

After a while will ask about your email address used for the SSL certification. Once it is finished enter your domain name on a browser with /ghost to register as admin in your ghost blog.

Secure a droplet

Back to my droplet, every time when I access to droplet with ssh default port is 22 and user is root, I should change default port and user root for protected

Create a new user named alex (you can change a name whatever you like)

adduser alex

and then there is a prompt to fill additional information and strong password.

Add permission to allow chai user run super user command

gpasswd -a alex sudo

Then, disable remote SSH access to the root account.

vi /etc/ssh/sshd_config

Next, I need to find the line that looks like this:

PermitRootLogin yes

change to

PermitRootLogin no

Then, change default port 22 to 1234 (up to you)

Port 1234

Finally, restart ssh service with

service ssh restart

Now, try to open another terminal and access to Digital Ocean with:

ssh chai@123.456.7.8 -p 1234

You can access like a root user. Well done!

Note: Use -p follow by port_number in case you change your default port

Redirect www to non-www

You may wish to have multiple domains that redirect to your blog, e.g. to have an extra TLD or to support www. domains. Ghost itself can only ever have one domain pointed at it. This is intentional for SEO purposes, however you can always redirect extra domains to your Ghost install using nginx.

If you want to redirect an HTTPS domain, you must have a certificate for it. This is where letsencrypt comes in particularly handy, because who wants to pay for SSL for a redirect?!

If you want to use Ghost-CLI to generate an extra SSL setup, you can do this using a little trick, first run ghost config to change the domain. This will not restart Ghost, so the change won't be reflected.

ghost config url https://www.example.com

Next, get Ghost-CLI to generate an SSL setup for your domain with www.:

ghost setup nginx ssl

You've now got two domains setup with SSL. Next, change your Ghost config back before you forget.

ghost config url https://example.com

Finally, you'll need to edit the nginx config files for your second domain to redirect to your canonical domain. Edit both files:

  • /var/www/ghost/system/files/www.example.com.conf
  • /var/www/ghost/system/files/www.example.com-ssl.conf

making the below changes:

/var/www/ghost/system/files/www.example.com.conf

Has to look like this:

server {
    listen 80;
    listen [::]:80;

    server_name www.example.com;
    root /var/www/ghost/system/nginx-root;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;

    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
    return 301 https://example.com$request_uri;
}

/var/www/ghost/system/files/www.example.com-ssl.conf

Similarly has to look as below.

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name www.example.com;
    root /var/www/ghost/system/nginx-root;

    ssl_certificate /etc/letsencrypt/www.example.com/fullchain.cer;
    ssl_certificate_key /etc/letsencrypt/www.example.com/www.example.com.key;
    include /etc/nginx/snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;

    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
    return 301 https://example.com$request_uri;
}

Once you have made those changes run

 sudo nginx -t 

to get nginx to verify your config, and

sudo nginx -s reload 

to reload nginx and pick up your new configuration.

Useful enhancements

  1. Add subscribe button

The Subscribers feature in Ghost allows you to capture email addresses of people who would like to subscribe to your publication's content. Email addresses can be viewed and edited from Ghost admin, but no emails will be sent without further integrations with an email tool.This feature can be enabled in the "Labs" settings menu in Ghost admin. When it is enabled, a subscribe button will appear on your site, if your theme supports it.

The subscribe button appears on the far right using the Casper theme!

When the Subscribers feature is enabled, a “Subscribers” menu item will appear within Ghost Admin:

This menu allows you to manage your subscriber list with the following actions:

  • Adding subscribers manually
    Click the “Add Subscriber” button to add the subscriber email address.
  • Deleting subscribers
    Hover over the subscriber email address and click on the trashcan icon.
  • Import a subscriber list
    Use the “Import CSV” and “Export CSV” buttons. Imports must be in CSV format, e.g. email, email@email.com, email2@email.com.

2. Google Analytics

Follow this link: https://docs.ghost.org/integrations/google/

Conclusion

That's it! This should help you set up and running your own blog, so you can actually focus your time on writing something. I tend to like this hands-on approach especially when I want to learn some new tricks. If this scares you, you can always use the managed version Ghost(Pro) which will abstract away pretty much all the above tasks.

At this point I would like to give special thanks to my friend PicoCoder for all of his help and guidance. Please do check his blog.