Have you decided to start blogging but confused about how to setup a blog? Just read this blog where I have listed all the things you need to do for getting your blog up and running using ghost, digital ocean and lets encrypt.

Medium VS WordPress VS Ghost?

You can setup a blog using a number of ways, a few popular once listed here:

Medium Word Press Ghost Ghost Self Hosted
Costing Free ₹255 /month, billed annually ₹255 /month, billed annually ₹355 /month
Features Custom platform for blogging Simple Simplest Simplest and you own everything.
Downside Limited customizations Can get a bit complicated A bit costly. Need to setup

Using ghost on a self-hosted virtual machine provides you total control over everything related to your blog.

I loved the ghost user interface and ease of editing it provides along with flexibility in options to customize anything later.

Self Hosted VS Managed Hosting

Wordpress and ghost both offer managed hosting by hosting your blog on shared hosting. This quickly helps in getting setup with your blog.

Although if you are really serious about blogging and wish to control all aspects you can choose to host your blog on a custom vm using digital ocean or any other provider.

Which Hosting To Use

To start its usually best to go with a basic vm and then scale the server once you get more traffic.

AWS Azure Google Cloud Digital Ocean
Hardware t2.micro A0 f1-micro standard
Ram Memory 1 GB 0.75 GB 0.6 GB 1 GB
Costing Per Month 8$ 14.65$ 4.65$ 5$

Digital ocean provides easy to use ui to create and manage new vms.

How To Create Your SSH Key

SSH Keys are used to login to virtual machines on the cloud. You will need this key to setup your digital ocean account in next steps.

# Creating your ssh key
ssh-keygen

Just visit https://cloud.digitalocean.com/account/security.

You will need to copy the content of the file id_rsa.pub and paste it while adding your key on digital ocean.

How to create a droplet in Digital Ocean?

  • Go to create a new droplet, once you sign up on digital ocean.
  • Select the type of droplet. For starting new we can begin with:
  1. 18.04.2X64 Ubuntu.
  2. Standard Plan.
  3. 1 Gb, 25 Gb SSD Disk and 1000 Gb Transfer
  • Select your closest datacenter for the vm. Closer the server is your target audience faster will the website load.
  • Add your ssh key for accessing the droplet.
  • Finally, choose a name for the droplet and click create

It will take a few seconds to create the droplet for you and it should be up and running.

You can view all the information about this droplet. Just copy the ipv4 address for pointing your domain to this droplet.

Linking Your Domain To Droplet

Go to the dns management section on your dns provider website and add a A record pointing to the

Setting Up Our Droplet With Ghost On Docker and Https with certbot

  • Login to the droplet using ipv4 address and user as root.
ssh root@159.89.161.23
  • Create a new user and allow sudo access to this user
adduser nilesh
usermod -aG sudo nilesh
  • Copy your ssh key to the newly created user from your machine
cat ~/.ssh/id_rsa.pub | ssh root@newblog.techinertia.com "mkdir -p /home/nilesh/.ssh && cat >> /home/nilesh/.ssh/authorized_keys"
  • Login using the new user
ssh nilesh@159.89.161.23
  • Install ufw, nginx, docker, software properties and certbot
# Setup firewall
sudo apt install ufw
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

# Install Docker
curl -sL https://get.docker.com | sh
sudo usermod -aG docker nilesh

# Install Nginx
sudo apt install nginx

# Install software properties and certbot
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt-get install python-certbot-nginx
  • Update nginx configurations to run certbot https verifications. Update the file /etc/nginx/sites-available/default
server {
	listen 80;
	server_name newblog.techinertia.com;
	location /.well-known/ {
		root /var/www/newblog.techinertia.com/;
	}

	location / {
		return 301 https://$server_name$request_uri;
	}
}
  • Create a folder for new blog files
mkdir /var/www/newblog.techinertia.com
  • Run the following commands to run certbot verification
sudo certbot --authenticator webroot --installer nginx
  • Enter the folder path when prompted for webroot.
  • Select redirect all traffic page to HTTPS.
  • Now update your nginx config file to below settings
server {
	server_name newblog.techinertia.com;
	listen 443 ssl;

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

	}

	ssl_certificate     /etc/letsencrypt/live/newblog.techinertia.com/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/newblog.techinertia.com/privkey.pem;
	ssl on;

}
  • Install docker image for ghost
docker run --name ghost \
 -p 127.0.0.1:2368:2368 \
 -e url=https://newblog.techinertia.com \
 -v /home/nilesh/ghost/content:/var/lib/ghost/content \
 --restart=always \
  • Check newblog.techinertia.com and you should be up and running.
  • Just visit newblog.techinertia.com/ghost and complete the setup by creating your user.

Conclusion

Self-hosted ghost blog using digital ocean provide a simple way to maintain your blog while owning everything on your platform.

If you are willing to create a brand for your blog, monetize the incoming traffic and create a strong reputation for your domain you should use the combination described above to setup your blog.