How to deploy Ghost Blog with Nginx on Ubuntu 20.04

Ghost is a free, open-source, and lightweight blogging platform built on Node.js. It is simple, customizable, and allows you to create and publish your content on the internet. It is specially designed for blogging so it is much faster than other blogging platforms. It offers a rich set of features, some of them are listed below:

  • Markdown editor
  • Scheduled publishing
  • Provide application for Linux, Mac, and Windows
  • Provides hundreds of free and premium themes
  • Built-in analytics
  • Provide migration plugin to migrate from WordPress to Ghost

This tutorial will explain how to install the Ghost with Nginx and Let's Encrypt SSL on Ubuntu 20.04.

Prerequisites

  • A server running Ubuntu 20.04.
  • A valid domain name pointed to your server IP.
  • A root password is configured on your server.

Getting Started

First, it is recommended to update the APT package cache to the latest version. You can update it with the following command:

apt-get update -y

Once the APT cache is updated, install other required dependencies using the following command:

apt-get install gnupg2 curl unzip git acl -y

Next, you will also need to install the Node.js to your system.

First, add the Node.js repository with the following command:

curl -sL https://deb.nodesource.com/setup_12.x | bash -

Once the repository is installed, run the following command to install the Node.js to your system.

apt-get install nodejs -y

Once the installation is finished, verify the Node.js version using the following command:

node -v

You should get the following output:

v12.22.1

Next, verify the NPM version with the following command:

npm -v

You should get the following output:

6.14.12

Install Nginx and MariaDB

Next, you will need to install the Nginx web server and MariaDB database server to your system. You can install both packages with the following command:

apt-get install mariadb-server nginx -y

Once the installation is finished, secure the MariaDB installation and set the MariaDB root password with the following command:

mysql_secure_installation

Answer all the questions to secure the MariaDB installation:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Next, log in to MariaDB with the following command:

mysql -u root -p

Once login, create a database and user for Ghost with the following command:

MariaDB [(none)]> CREATE DATABASE ghostdb;
MariaDB [(none)]> CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'password';

Next, grant all the privileges to the Ghost database with the following command:

MariaDB [(none)]> GRANT ALL ON ghostdb.* TO 'ghostuser'@'localhost';

Next, flush the privileges and exit from the MariaDB with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Once you are finished, you can proceed to the next step.

Install Ghost Cli

Next, you will need to install the Ghost Cli to install and manage the Ghost. You can install it using the NPM as shown below:

npm install -g [email protected]

Once installed, verify the installed version of Ghost Cli with the following command:

ghost version

You should see the following output:

Ghost-CLI version: 1.16.3

Install Ghost

First, create a separate user for Ghost with the following command:

adduser user1

Next, add user1 to sudo and www-data group with the following command:

adduser user1 sudo
adduser user1 www-data

Next, log in with user1 and create a directory for Ghost with the following command:

su - user1
sudo mkdir /var/www/ghost

Next, set proper permission and ownership with the following command:

sudo chown -R www-data:www-data /var/www/ghost
sudo chown -R www-data:www-data /var/www/
sudo chmod 775 /var/www/ghost
sudo setfacl -R -m u:user1:rwx /var/www/ghost/

Next, change the directory to ghost and install the Ghost blogging platform with the following command:

cd /var/www/ghost
ghost install

You will be asked to provide your blog URL, database name, username, password and other information as shown below:

? Enter your blog URL: https://ghost.linuxbuz.com
? Enter your MySQL hostname: localhost
? Enter your MySQL username: ghostuser
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghostdb
? Configuring Ghost
? Setting up instance
+ sudo useradd --system --user-group ghost
+ sudo chown -R ghost:ghost /var/www/ghost/content
? Setting up "ghost" system user
? Setting up "ghost" mysql user [skipped]
? Do you wish to set up Nginx? Yes
+ sudo mv /tmp/ghost-linuxbuz-com/ghost.linuxbuz.com.conf /etc/nginx/sites-available/ghost.linuxbuz.com.conf
+ sudo ln -sf /etc/nginx/sites-available/ghost.linuxbuz.com.conf /etc/nginx/sites-enabled/ghost.linuxbuz.com.conf
+ sudo nginx -s reload
? Setting up SSL [skipped]
? Do you wish to set up Systemd? Yes
+ sudo mv /tmp/ghost-linuxbuz-com/ghost_ghost-linuxbuz-com.service /lib/systemd/system/ghost_ghost-linuxbuz-com.service
+ sudo systemctl daemon-reload
? Setting up Systemd
+ sudo systemctl is-active ghost_ghost-linuxbuz-com
? Do you want to start Ghost? (Y/n) 

At this point, Ghost is installed and started.

Secure Ghost with Let's Encrypt SSL

Next, you will need to secure Ghost with Let's Encrypt SSL.

First, install the Certbot client with the following command:

sudo apt-get install certbot python3-certbot-nginx -y

Once installed, run the following command to download the Let's Encrypt SSL and configure Nginx to use those certificate:

sudo certbot --nginx -d ghost.linuxbuz.com

You will be asked to provide your email address and accept the term of service as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for ghost.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/ghost.linuxbuz.com.conf

Next, choose whether or not to redirect HTTP traffic to HTTPS:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and hit Enter to complete the installation.

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/ghost.linuxbuz.com.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://ghost.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=ghost.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/ghost.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/ghost.linuxbuz.com/privkey.pem
   Your cert will expire on 2021-07-13. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Now, you can verify the Ghost website with the following command;

ghost ls

You should see the following output:

+ sudo systemctl is-active ghost_ghost-linuxbuz-com
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
? Name               ? Location       ? Version ? Status               ? URL                        ? Port ? Process Manager ?
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
? ghost-linuxbuz-com ? /var/www/ghost ? 4.2.1   ? running (production) ? https://ghost.linuxbuz.com ? 2368 ? systemd         ?
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

You can also verify the Ghost service with the following command:

sudo systemctl status ghost_ghost-linuxbuz-com

You should see the following output:

? ghost_ghost-linuxbuz-com.service - Ghost systemd service for blog: ghost-linuxbuz-com
     Loaded: loaded (/lib/systemd/system/ghost_ghost-linuxbuz-com.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-04-14 07:05:33 UTC; 9min ago
       Docs: https://ghost.org/docs/
   Main PID: 7546 (node)
      Tasks: 22 (limit: 2353)
     Memory: 134.3M
     CGroup: /system.slice/ghost_ghost-linuxbuz-com.service
             ??7546 ghost run
             ??7590 /usr/bin/node current/index.js

Apr 14 07:13:44 ubuntu node[7590]: [2021-04-14 07:13:44] INFO "GET /ghost/assets/img/dashboard/start-membership-baafa2c6558d118ae59cb1fddab045>
Apr 14 07:13:44 ubuntu node[7590]: [2021-04-14 07:13:44] INFO "GET /ghost/assets/img/dashboard/the-browser-f5e7e199fe82d8435913e84d022fa7e1.pn>
Apr 14 07:13:44 ubuntu node[7590]: [2021-04-14 07:13:44] INFO "GET /ghost/assets/img/dashboard/join-community-bb5478f7dca6c04a2d0baf2b02f880fb>
Apr 14 07:13:44 ubuntu node[7590]: [2021-04-14 07:13:44] INFO "GET /ghost/api/canary/admin/members/?filter=status%3Apaid&order=created_at%20as>
Apr 14 07:14:11 ubuntu node[7590]: [2021-04-14 07:14:11] INFO "GET /" 200 475ms
Apr 14 07:14:11 ubuntu node[7590]: [2021-04-14 07:14:11] INFO "GET /" 200 480ms
Apr 14 07:14:15 ubuntu node[7590]: [2021-04-14 07:14:15] INFO "GET /members/api/site/" 200 12ms
Apr 14 07:14:18 ubuntu node[7590]: [2021-04-14 07:14:18] INFO "GET /" 304 142ms
Apr 14 07:14:25 ubuntu node[7590]: [2021-04-14 07:14:25] INFO "GET /members/api/site/" 304 4ms
Apr 14 07:14:26 ubuntu node[7590]: [2021-04-14 07:14:26] INFO "GET /members/api/member/" 401 4ms

Access Ghost Admin Interface

Now, open your web browser and access the Ghost admin interface using the URL https://ghost.linuxbuz.com/ghost/. You should see the following page:

Ghost Blog installer

Click on the Create your account button to create your first account:

Create your account

Provide your account details and click on the I’ll do this later at the bottom of the screen. You should see the Ghost admin interface in the following page:

Ghost CMS Dashboard

You can also access your Ghost website using the URL https://ghost.linuxbuz.com/. You should see the following page:

Ghost CMS Frontend

Conclusion

Congratulations! you have successfully installed the Ghost blogging platform on Ubuntu 20.04. You can now create and publish your own content from the Ghost interface.

Share this page:

Suggested articles

1 Comment(s)

Add comment

Comments

By: Itannaseda at: 2021-05-05 14:36:04

I like this idea, I completely with you agree.