Hosting two or more Ghost Blog from a single server

Vijay Pushkin
11 min readDec 12, 2018

--

If you have finally decided to enter the world of blogging penning down all the ideas, theories, questions, answers that had accumulated in your brain since the day you questioned Einstein’s theory of General Relativity in your high school in not just one, but multiple blogs and told your mom about it who then got excited and wanted you to create one for her and her cat, or you and your blogging buddy decided to move your articles from medium.com/yourblog, yourblog.blogger.com,or yourblog.wordpress.com to your own custom domain but can’t afford renting multiple servers at the same time and have no idea how to do it either, you have landed at the right page. (Pheeew.. Lemme catch my breath for a second)

This tutorial is a complete beginner’s guide, you should be able to follow it unless you’re a caveman dwelling under the rock. If you’re able to write and publish blogs then you should be able to run your own blog. At the end this tutorial you’ll have a basic knowledge of running a server. Hello there Junior System Admin 😉

Before jumping right into it you have to do some deliberation, meditation, self-reflection and a couple of unrelated break through!

deliberating, meditating and self reflecting

Should you use custom domain for your blog?

Ask yourself these questions:

  • Am I writing about conspiracy theories and exposing the government and other big shots?
  • Am I writing about sensitive topics, topics that might offense someone or topics that is considered as taboo by the modern society.
  • Am I writing about natural beauty or health tips that would eventually kick Olay, Nivea and other cosmetics and pharmaceutical companies out of business?
  • Am I fed up with the boring templates that Blogger and WordPress provides me and need to change the visuals of my site as per my taste?
  • Should my site be SEO (Search Engine Optimized) id est, should my site appear at the top in Google search results?
  • Should I need a recognition amongst my peers or around my group and should my website name be easily to remember?
  • Should I need top advertiser advertise on my blog, so that my passive income triples?

If you’re a conspiracy theorist most of the people would advice you not to host your blog in some blogging platform’s domain, as they have full control over your content and will take your site down if the government or big shots wanted it. Same goes for the second and third, except it would be angry twitter warriors and big pharma companies respectively who would be upset about your blog and wanted it to be removed ASAP. We’ll talk about fourth one later. Google and other search engines always favors top level domains so are the top advertisers. Do you think top advertisor would be happy to publish their ads on a website yourblog.something.something.com or does Google prefers it to other websites like awesomeblog.com? God! My old blog was showing up in second and third page of Google’s search results, which was not good at all. Using your own custom domain makes a huge difference in terms of search results and attracting many advertiser (if you wish to monetize your hobby). Your friends and fans can easily remember your website’s name making them to visit often.

If you have answered yes to less than two questions then stop right here, this isn’t for you, you’re just wasting your time. Adios Amigo! 👋

Ready?

Getting Started (Photo by Will O on Unsplash)

Getting Started

1. Buying domain names:

First you should buy a domain name for yourself and buddy or your mom and her cat. You can use Instant Domain Search to choose your domain and buy it from GoDaddy or other domain providers. I brought three domains from godaddy for less than ₹300 ($4) each for the first year. My personal domain was just ₹149 ($2).

2. Generating a SSH key:

Remote login will save you from booking tickets to Germany with your keyboard, mouse and monitor every time if there is something you have to change in your server. You can control the server that is half way across the globe from your own PC. You just need to have a password for it.

But what if someone hacked into my server or I told others my password when I am drunk? 😕

This is why we use SSH key. Secure Shell (SSH) key is a cryptographic key that are just hard if not impossible to crack and can be used only from that PC where it was generated. So don’t worry about accidentally sharing your password or hacking.

To generate SSH key you need Git or PuTTy. I recommend using Git. Git is a open source version control that makes updating and reverting your changes in your programming file or text file easier. Download the appropriate version from here and install it. After installation open Git GUI. Then click Show SSH key from the help menu. upon clicking Generate Key, it will ask you to create a passphrase (password). You will using this every time you login into your server. Finally it will generate your key. Save the .ssh key in default location unless you know what you’re doing. Keep the window open for a while, you need to paste the code in the next step.

3. Renting a Virtual Machine (VM):

Virtual Machines are virtual machine that runs inside a real machine. You have plethora of options to choose from. Big guys like Google, Amazon and Microsoft offers one year worth of service for free, but I don’t recommend using them as of now and save it for later when your site blooms. I chose DigitalOcean. Their basic VM costs just $5 per month. It has 1GB of ram and 25GB of SSD which should satisfy the initial traffic. If you prefer other provider you’re free to do so, but in this tutorial we’ll be using DigitalOcean.

Head over to their site and create an account. Upon creation you’ll will be redirected to your dashboard. Now you have add $5 to your account credit. They also provide 60 days worth of credits for free to new users, use that if that’s available. Finally click on “Get Started with Droplets” from your dashboard.

Droplet is just their fancy name for Virtual Machine.

Select,

  • Distrubution → Ubuntu 18
  • Droplet Size → $5/mo
  • Add Backup → Add if needed else skip
  • Datacenter → <default>
  • Additional Options → IPv6, Monitoring
  • SSH keys → Paste the code copied from Git GUI and enter the name of your PC
  • Hostname → Name your server

Then create. It takes few seconds to initialize your virtual machine. Upon completion the IP address of machine will be shown.

4. Redirecting your domain address to the your new machine.

Head over to your domain provider dashboard. From there navigate to DNS settings of your domain address.

Scroll down and find Nameservers section. Select Custom Nameserver and add the following entries.

ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com

Now head back to your DigitalOcean dashboard and add your domain to your machine from its kebab menu ( • • •). Click on the domain card and make sure your it has one ‘A’ record and three ‘NS’ records. If ‘A’ record is missing add it

Hostname                ip                    ttl
@ <machine's ip> 3600

Then copy your machine’s ip address and head over to the next step.

5. Setting up your machine:

Open PowerShell (Windows) or Terminal (Mac or Linux) and type,

$ ssh root@<ip_address>
blah blah blah
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '<ip_address>' (ECDSA) to the list of known hosts.
Enter passphrase for key 'C:\Users\<you>/.ssh/id_rsa': <passphrase>

Voila! You have remotely logged in to your virtual machine. First, we need to make sure everything is up to date. Update your machine by running

$ apt-get update && apt-get upgrade

Now let’s add some users,

adduser <you>

Then type in your user password and fill in few other details like your name. Then add the new account to sudo user group. Sudo command allows you to perform certain admin tasks without logging in to the root account.

# Add your account to superuser group to unlock admin privileges
$ usermod -aG sudo <you>

# Then log in as the new user
$ su - <you>

Now let’s install a server,

# Install NGINX
$ sudo apt-get install nginx
# allow HTTP and HTTPS connections in your firewall
$ sudo ufw allow 'Nginx Full'

Next, you’ll need to install MySQL to be used as the production database (DB).

# Install MySQL
$ sudo apt-get install mysql-server

Setup MySQL DB

# To set a password, run
sudo mysql

# Now update your user with this password
# Replace 'password' with your password, but keep the quote marks!
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

# Then exit MySQL
quit

Install Node.js — NPM

# Add the NodeSource APT repository for Node 10 LTS
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

# Install Node.js
$ sudo apt-get install -y nodejs

Most of it might sound gibberish to you, but not to worry, just paste the commands and follow the on screen instruction for now, you’ll be good to go.

6. Choosing a Blogging Platform

Choosing a Blogging Platform? But I thought we will be building our own blog from scratch.

Yes and no. We will be building our own blog but not from the scratch. There are tools and pre-built platforms available for running a blog. Medium and WordPress gives you the option to use their platform on your own domain for free. But there is a difference between using their platform in their domain versus using their platform in your own domain. Its like you’re working for them versus they are working for you. You are the owner and controller of your blog.

Major players in this area are Medium, WordPress and Ghost. Though WordPress in just simple, neat and customizable, it’s not an eye stunner. This is what I talking of in the 4th point above. Medium is modern, sleek and beautiful, but it has only one template which you can’t customize. Being a Front End engineer this greatly bothers me. Another reason of me not choosing Medium was it is a closed platform and they won’t allow advertisers on your site (which is good actually) and you have to use a payment service — Stripe which isn’t available here in India yet and it doesn’t offer much freedom as WordPress does. Don’t get me wrong Medium is a great platform and I would recommend it if you love their community and their payment system works in your country.

What if there was a platform that had the openness and customizibility as WordPress and is as gorgeous as Medium? Well! That’s Ghost for you ladies and gentlemen!

Ghost is powered by a modern technology stack using Node.js – it’s fast. Really, really, really, ridiculously fast.

Independent tests have found Ghost to be up to 1,900% faster than WordPress. What does that mean? In the amount of time it takes WordPress to respond to 1 request, Ghost will have already responded to 19 of them. The speed of your blog impacts everything, from search engine rankings to mobile user engagement.

Ghost is used by many companies like Mozilla (owner of Firefox), Duckduckgo (Google Search’s competitor), Speedtest, Dailymotion, Vevo et cetera.

It’s highly customizible that you can add your own HTML CSS and change it’s look and feel entirely. It is built from Handlebar.js which is highly SEO’ed (Search Engine Optimized) which other JavaScript frameworks like React and Angular isn’t proud of. There is also lots of themes available on Theme Forest for Ghost. Just download the zip and add it to your Ghost Dashboard. It’s that simple. It doesn’t require any coding knowledge.

7. Install Ghost:

Ghost-CLI is a commandline tool to help you get Ghost installed and configured for use, quickly and easily. Remember we installed Node.js? Node.js is the server side JavaScript engine that will run these apps. They are like webapps running directly on the OS instead of a browser, thanks to Node.js.

# NPM is Node Package Manager
$ sudo npm install ghost-cli@latest -g

Create directory where your first blog will be installed

# Replace <yourblog> with your blog name or whatever would be easy 
# for you to identify
sudo mkdir -p /var/www/<yourblog>

# Replace <user> with your username that you created
sudo chown <user>:<user> /var/www/<yourblog>

# Set the correct permissions
sudo chmod 775 /var/www/<yourblog>

# Then navigate into it
cd /var/www/<yourblog>

Now you’ve made it this far, it’s time to install Ghost with a single command 😀

ghost install

Questions?

  • Blog URL → <your_domain_address>
  • MySQL hostname → <default>
  • MySQL username → root
  • MySQL password → <your MySQL password>
  • Ghost database name → <default>
  • Do you wish to set up “ghost” mysql user? → Yes
  • Do you wish to set up Nginx? → Yes
  • Do you wish to set up SSL? → Yes
  • Enter your email (For SSL Certificate) → <email_address>
  • Do you wish to set up Systemd? → Yes
  • Do you want to start Ghost? → Yes

For detailed information about each questions visit ghost.org

Let it install and upon completion it will prompt you to visit yourblog.com/ghost to set up admin account.

Create an admin account and explore your new blog.

Congratulations on creating your new blog! If you’re here to create only one blog, you stop here now. Au Revoir!👋

8. Adding additional blogs:

Now it’s time to add blogs for your buddy, mom and her cat!

Repeat step no. 4 for your second blog. Make sure you have given your virtual machine’s ip address.

Since you’re now experience we will run through this process quickly

# Logout from your user account and use root
$ logout
# Create a new user and follow prompts
$ adduser <user2>
# Add user2 to superuser group to unlock admin privileges
$ usermod -aG sudo <user2>

# Then log in as the new user if your friend is not nearby
$ su - <user2>
# Open mysql and type password when prompted
$ mysql -u root -p
# Create separate MySQL user account
# Replace user2 and password but DO NOT remove the quotes
mysql> CREATE USER 'user2'@'localhost' IDENTIFIED BY 'password';
# Grant previlages
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user2'@'localhost';
mysql> exit
# Create directory for your secondblog
sudo mkdir -p /var/www/secondblog

# Change the ownership
sudo chown <user2>:<user2> /var/www/secondblog

# Set the correct permissions
sudo chmod 775 /var/www/secondblog

# Then navigate into it
cd /var/www/secondblog
# Now install, and answer as below
ghost install

Questions,

  • Blog URL → <second_domain_address>
  • MySQL hostname → <default>
  • MySQL username → <user2>
  • MySQL password → <user2 MySQL password>
  • Ghost database name → <default>
  • Do you wish to set up “ghost” mysql user? → No
  • Do you wish to set up Nginx? → Yes
  • Do you wish to set up SSL? → No
  • Enter your email (For SSL Certificate) → <friend_email_address>
  • Do you wish to set up Systemd? → Yes
  • Do you want to start Ghost? → No

Notice how we didn’t setup new mysql user “ghost” and ssl certificate and didn’t start ghost. It’s because we have few changes to make.

# Head over to NGINX conf directory
$ cd /etc/nginx/sites-enabled/
# Stop NGINX server
$ sudo service nginx stop
# Open editor and modify secondblog file
$ nano secondblog.com.conf

Change the port number to any number you wish as long as it isn’t occupied by another process.

...
location / {
...
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:<port>;
}
...

Imagine that a server is like a big harbor, which has many ports for ships to dock. You don’t want two ship being docked in the same port, do you? So you should assign second blog some other port.

Server and Ports (Photo by Adam Seckel on Unsplash)

Now let’s set up SSL and start ghost

# start NGINX server
$ sudo service nginx start
# move to secondblog directory
$ cd /var/www/secondblog
# Set SSL
$ ghost setup ssl
# Start Ghost
$ ghost start

✨ You have successfully hosted multiple blogs from the same server. Hope you found this tutorial useful. Now go create some awesome blog posts.🎉

--

--