Install Ghost CMS on Ubuntu 22.04|20.04|18.04

Posted on 33 views

This guide will demonstrate how to install Ghost on Ubuntu 22.04|20.04|18.04 Linux distributions. The installation will be for a production blog and we’ll secure it with Let’s Encrypt SSL certificate and redirect all http traffic to https.

Installation of Ghost on Ubuntu 22.04|20.04|18.04 is a straightforward automated process. It will configure systemd unit for managing the blog service and generate nginx configuration files for you. The only manual task you have is to answer some simple questions during installation and test settings.

What’s Ghost CMS?

Ghost is an open source publishing platform which is beautifully designed, easy to use, and free for everyone. It has full support for Markdown and provides an easy to use the web interface for administration purposes.

Requirements

For this setup, the basic requirements are:

  • Ubuntu Linux system
  • Nginx installed and running
  • FQDN – e.g blog.example.com
  • Node.js
  • MySQL
  • ghost user – Non-root user to manage it

We recommend you perform an upgrade and reboot the system before you start installation process:

sudo apt update && sudo apt -y full-upgrade

Then reboot the OS if required:

[ -f /var/run/reboot-required ] && sudo reboot -f

Let’s go to the installation section for the requirements:

Step 1: Installing Nginx on Ubuntu / Debian

Get nginx installed on your server by running:

sudo apt install vim nginx

Step 2: Installing MySQL DB server on Ubuntu / Debian

Ghost requires MySQL to store its data. Let’s install MariaDB database server:

sudo apt install mariadb-server

Start and enable mariadb service:

sudo systemctl enable --now mariadb

Create the database for ghost blog we intend to add:

$ sudo mysql -u root -p
create database myblog;
grant all on myblog.* to myblog@localhost IDENTIFIED By "Str0ngPassw0rd";
flush privileges;
exit;

Step 3: Add User for Ghost administration

Create a user for ghost CMS:

sudo adduser ghostcms
sudo usermod -aG sudo ghostcms

We’ll later use this user for all Ghost related administration.

Step 4: Install Node.js on Ubuntu / Debian

We need to have Node.js installed on the system before we’re able to start using Ghost. Install it using the commands:

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash 
sudo apt install -y nodejs

Confirm success of Node.js installation:

$ node --version
v16.14.2

It is stated in the documentation that NVM doesn’t work well with Ghost, you need to first uninstall it if you have it on your system.

Please uninstall nvm and any node versions installed with it:

rm -rf $NVM_DIR ~/.npm ~/.bower
unset NVM_DIR;
which node;
rm -rf path_to_node_version

Also look in your ~/.bash_profile or ~/.bashrc and remove any nvm lines.

Step 5: Install Ghost-CLI on Ubuntu 22.04|20.04|18.04

We now need to install the package ghost-cli which provides ghost command.

$ sudo npm i -g ghost-cli
added 427 packages, and audited 428 packages in 21s

$ sudo npm i -g [email protected]

If you install Ghost via the CLI for production, you need to have met the pre-requisites and installed ghost-cli.

Checking Ghost CLI version:

$ ghost -v
Ghost-CLI version: 1.18.2

Step 6: Create a new folder for Ghost Data

Please note that:

  • Installing Ghost in the /root folder won’t work and result in a broken setup!
  • Installing Ghost in your /home/user folder won’t work and result in a broken setup!
  • Please only use /var/www/folder because it has the right permissions.

So let’s create this directory:

sudo mkdir -p /var/www/ghostcms
cd /var/www/ghostcms

Then let’s make the user we created earlier to own this directory.

sudo chown ghostcms:ghostcms /var/www/ghostcms
sudo chmod 775 /var/www/ghostcms

Step 7: Install Ghost using Ghost-CLI

You have to run ghost within the directory you would like to install Ghost. Also, note that the directory has to be empty.

sudo su - ghostcms
cd /var/www/ghostcms
mkdir blog.example.com
cd blog.example.com

Run the command below to install ghost:

$ ghost install
✔ Checking system Node.js version - found v16.14.2
✔ Checking logged in user
✔ Checking current folder permissions
✔ Checking system compatibility
✔ Checking for a MySQL installation
✔ Checking memory availability
✔ Checking free space
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v4.41.0
✔ Finishing install process
? Enter your blog URL: https://blog.example.com
? Enter your MySQL hostname: (localhost) localhost
? Enter your MySQL username: myblog
? Enter your MySQL password: [hidden] Str0ngPassw0rd
? Enter your Ghost database name: myblog
✔ Configuring Ghost
✔ Setting up instance
+ sudo useradd --system --user-group ghost
? Do you wish to set up "ghost" mysql user? Yes
✔ Setting up "ghost" system user
ℹ Setting up "ghost" mysql user [skipped]
? Do you wish to set up Nginx? Yes
+ sudo mv /tmp/blog-example-com/blog.example.com.conf /etc/nginx/sites-available/blog.example.com.conf
+ sudo ln -sf /etc/nginx/sites-available/blog.example.com.conf /etc/nginx/sites-enabled/blog.example.com.conf
+ sudo nginx -s reload
✔ Setting up Nginx
  • This will install and start your blog in production mode using MySQL as the default database

Nginx configuration files will be placed under: /etc/nginx/sites-enabled/

Using Let’s Encrypt SSL certificate

If your server has a public IP address and valid Domain name with A record mapped, you can configure https using free Let’s Encrypt SSL certificate.

? Do you wish to set up SSL? (Y/n) y

Input email address that will receive alerts for Certificate expiration:

? Enter your email (For SSL Certificate) [email protected]

The process of SSL request is automated.

+ sudo mkdir -p /etc/letsencrypt
+ sudo ./acme.sh --install --home /etc/letsencrypt
+ sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --server letsencrypt --domain blog.example.com --webroot /var/www/ghostcms/blog.example.com/system/nginx-root --reloadcmd "nginx -s reload" --accountemail [email protected]
+ sudo openssl dhparam -dsaparam -out /etc/nginx/snippets/dhparam.pem 2048
+ sudo mv /tmp/ssl-params.conf /etc/nginx/snippets/ssl-params.conf
+ sudo mv /tmp/blog-example-com/blog.example.com-ssl.conf /etc/nginx/sites-available/blog.example.com-ssl.conf
+ sudo ln -sf /etc/nginx/sites-available/blog.example.com-ssl.conf /etc/nginx/sites-enabled/blog.example.com-ssl.conf
+ sudo nginx -s reload

Configure Systemd and start service:

? Do you wish to set up Systemd? Yes
+ sudo mv /tmp/blog-example-com/ghost_blog-example-com.service /lib/systemd/system/ghost_blog-example-com.service
+ sudo systemctl daemon-reload
✔ Setting up Systemd
+ sudo systemctl is-active ghost_blog-example-com
? Do you want to start Ghost? Yes
+ sudo systemctl start ghost_blog-example-com
+ sudo systemctl is-enabled ghost_blog-example-com
+ sudo systemctl enable ghost_blog-example-com --quiet
✔ Starting Ghost

Ghost uses direct mail by default. To set up an alternative email method read our docs at https://ghost.org/docs/config/#mail

------------------------------------------------------------------------------

Ghost was installed successfully! To complete setup of your publication, visit:

    https://blog.example.com/ghost/

If you chose to setup systemd, then your systemd unit will be created, whose symlink is:

$ ls -lh /lib/systemd/system/ghost_blog-example-com.service
/lib/systemd/system/ghost_blog-example-com.service -> 
/var/www/ghost/blog.example-com/system/files/ghost_blog-example-com.service

To manage the service with this unit, use:

$ sudo systemctl  ghost_blog-computingforgeeks-com.service

Some Ghost troubleshooting Cheats:

Logs dir: /content/logs/

  • $ ghost start: Start ghost
  • $ ghost restart: Restart ghost
  • $ ghost run: Test if the ghost can start successfully
  • $ ghost uninstall: Re-install ghost
  • $ ghost update: Upgrade ghost
  • $ ghost update --force: Force upgrade if there are errors
  • $ ghost update --rollback: Revert to the earlier version if an upgrade fails
  • $ sudo npm i -g [email protected]: Upgrade Ghost-CLI
  • $ ghost ssl-renew: Renew ssl certificate
  • $ ls ./system/files/*.conf: System configuration files
  • $ ghost setup nginx: Manually Setup nginx
  • $ ghost setup nginx ssl: Setup nginx with SSL

Step 8: Accessing Ghost Admin interface

Your setup is now ready, access Ghost web admin interface where you can upload themes, change settings and write content using markdown syntax.

  • https://blog.example.com/ghost

Replace the URL with your valid URL. When you are accessing it for the first time, it will ask you to create first admin user account.

install-ghost-ubuntu-create-user-1024x834

Once account is created you’re logged in to the Ghost CMS administrative dashboard.

ghost-cms-dashboard-1024x298

Authors, editors and collaborators can be managed from the settings section.

ghost-cms-settings-1024x477

In our next article, I’ll cover using markdown to writing content for Ghost and how to add themes and other customizations to Ghost website.

 

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.