How to Install Ghost on Ubuntu 20.04

Ghost is a lightweight open-source blogging platform. The Ghost user interface is very simple and straightforward making it great for beginners as well as advanced users.

In the following tutorial, we will show you all the requirements and instructions needed to install Ghost on Ubuntu 20.04 OS.

Requirements:

  • For the purposes of this tutorial, we will use an Ubuntu20.04 VPS.
  • Nginx Web Server
  • MySQL / MariaDB Database Server
  • Node.js LTS version
  • Domain or Subdomain (e.g ghost.yourdomain.com) pointed to your server IP address
  • Ghost user (user with sudo privileges)

Step 1: Log in to the Server & Update the Server OS Packages

First, log in to your Ubuntu 20.04 server via SSH as the root user:

ssh root@IP_ADDRESS -p PORT_NUMBER

Don’t forget to replace IP_Address and Port_Number with your server’s actual IP address and the SSH port number. Also, you should replace ‘root’ with the username of the admin account if needed.

Once you are in, run the following commands to update the package index and upgrade all installed packages to the latest available version

apt-get update 
apt-get upgrade

Step 2: Add Ghost user

To add a user for Ghost with sudo privileges run the following commands:

adduser ghostuser
adduser ghostuser sudo

Then switch to the ghost user.

su - ghostuser

Note: Using the user name ghost causes conflicts with the Ghost-CLI, so you need to use an alternative name.

Step 3: Install Nginx webserver

Nginx web server can be installed with the following command:

sudo apt-get install nginx

Once, the installation is complete you can check the status of the Nginx service:

sudo systemctl status nginx

You should get the following output:

● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-12-23 09:22:55 UTC;
Docs: man:nginx(8)
Main PID: 3423 (nginx)
Tasks: 2 (limit: 2245)
Memory: 4.4M
CGroup: /system.slice/nginx.service
├─3423 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─3425 nginx: worker process

Step 4: Install MariaDB Server

Run the following command to install the MariaDB server from the official Ubuntu repositories:

sudo apt-get install mariadb-server mariadb-client

Once installed, the MariaDB server should be automatically started.

You can check the status of the MariaDB service with the following command:

sudo systemctl status mariadb

Output:

● mariadb.service - MariaDB 10.3.32 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-12-23 09:28:03 UTC;
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 4489 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 31 (limit: 2245)
Memory: 66.8M
CGroup: /system.slice/mariadb.service
└─4489 /usr/sbin/mysqld

To enable MariaDB to automatically start upon server reboot run the following command:

sudo systemctl enable mariadb

Next, secure the MariaDB installation using the following command:

sudo mysql_secure_installation

This script will set the MariaDB root password, disable remote root login and remove anonymous users as shown below:

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

Step 5: Create Ghost Database

Ghost uses MySQL/MariaDB to store its contents. So you will need to create a database and user for Ghost.

First, log in to MariaDB with the following command:

sudo mysql -u root -p

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

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

Next, grant all the privileges to the Ghost database using the command below:

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

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

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

Step 6: Install Nodejs and NPM

Ghost is built on Node.js. Ghost requires you to install the LTS version of Node.js and does not support the non-LTS version.

Add the Node.js repository with the following command:

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

And install the Node.js from the added repositories running the following command:

sudo apt-get install nodejs

Once NodeJS has been installed, you can verify the installed version of Node.js with the following command:

node -v

You should get the following output:

v16.13.1

Once Node.js is installed, update the NPM to the latest version using the following command:

sudo npm install npm@latest -g

You can now verify the npm version with the following command:

npm -v

You should get the following output:

8.3.0

Step 7: Download and install Ghost

Now install the Ghost-CLI tool using NPM. It is a command-line interface (CLI) tool that makes installing and updating Ghost easy in a single command.

sudo npm install ghost-cli@latest -g

Create a directory (/var/www/ghost/) for Ghost.

sudo mkdir -p /var/www/ghost

Next, change the folder ownership to your ghost user so you can run the Ghost tool to download Ghost packages.

sudo chown ghostuser:ghostuser /var/www/ghost
sudo chmod 775 /var/www/ghost

Change into the directory and install Ghost.

cd /var/www/ghost

Run the following command to install ghost:

ghost install

You should begin to see Ghost changing for packages that are required. Once all is validated, Ghost should begin downloading its package dependencies to install.

 ✔ Checking system Node.js version - found v16.13.1
✔ 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.32.0 > Installing dependencies >

Answer each question as prompted.

? Enter your blog URL: http://yourdomain.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
 Setting up "ghost" system user
ℹ Setting up "ghost" mysql user [skipped]
? Do you wish to set up Nginx? Yes
? Do you wish to set up SSL? Yes
? Enter your email (For SSL Certificate)>[email protected]
? Do you wish to set up Systemd? Yes
? Do you want to start Ghost? Yes

Once the installation is complete, run ghost ls to view running Ghost processes:

 ghost ls

You should get the following output:

installing ghost on ubuntu 20.04

After that, open your browser and browse to the Ghost admin interface to complete the setup:

https://yourdomain.com/ghost/
setting up ghost on ubuntu 20.04

That’s it! The installation of Ghost on Ubuntu 20.04 has been completed.

Of course, you don’t need to install Ghost on Ubuntu 20.04 yourself if you use one of our fully managed Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install it for you. They are available 24×7 and will take care of your request immediately.

P.S. If you liked this post on how to install Ghost on Ubuntu 20.04 please share it with your friends on the social networks by using the share shortcuts below, or simply leave a comment in the comments section. Thanks.

1 thought on “How to Install Ghost on Ubuntu 20.04”

  1. Awesome guide. One small note:
    The command sudo curl -sL https://deb.nodesource.com/setup_16.x | bash needs to include “sudo” to rub bash after the |

    This worked for me 100%.
    Thank you

    Reply

Leave a Comment