Infrastructure 2 min read

Installing Ghost on Ubuntu

A quick no frills guide to installing Ghost blog on Ubuntu.

This is a "No-frills" guide to installing Ghost and its relevant dependancies on Ubuntu server.

Prerequisites

Before beginning the installation process, ensure you have:

  1. A Ubuntu server (20.04 or 22.04 recommended)
  2. Root or sudo access to the server
  3. A domain name pointed to your server's IP address

Step 1: Update System Packages

First, update your system packages:

sudo apt update
sudo apt upgrade -y

Step 2: Install Node.js

Ghost requires Node.js to run. Install the recommended version:

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

Verify the installation:

node --version
npm --version

Step 3: Install MySQL

Ghost uses MySQL as its database. Install it with:

sudo apt install mysql-server -y

Secure your MySQL installation:

sudo mysql_secure_installation

Step 4: Create a Ghost Database and User

Log into MySQL:

sudo mysql

Create a database and user for Ghost:
Change 'your_password' to your own password and change the username if you wish.

CREATE DATABASE ghost_db;
CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON ghost_db.* TO 'ghostuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 5: Install Ghost-CLI

Ghost-CLI is a command-line tool for installing and managing Ghost:

sudo npm install ghost-cli@latest-g

Step 6: Create Ghost Directory

Create a directory for your Ghost installation:

sudo mkdir -p /var/www/ghost
sudo chown $USER:$USER /var/www/ghost
sudo chmod 775 /var/www/ghost
cd /var/www/ghost

Step 7: Install NGINX

Install NGINX:

sudo apt install nginx

Ensure NGINX is running:

sudo systemctl status nginx

If its not running, start it manually:

sudo systemctl start nginx

Enable NGINX to start on boot:

sudo systemctl enable nginx

Step 8: Install Ghost

Now, install Ghost using the Ghost-CLI:

ghost install

During the installation, you'll be prompted to enter various details:

Accept the prompts to set up Nginx and SSL.

Step 9: Configure Nginx (if not done automatically)

If Nginx wasn't set up automatically, create a configuration file:

sudo nano /etc/nginx/sites-available/ghost

Add the following configuration (replace yourdomain.com with your actual domain):

server {
    listen 80;
    server_name yourdomain.com;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;
    }
}

Enable the configuration:

sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
馃挕
Make sure to point your DNS A record to your server IP.

Step 10: Set Up SSL (if not done automatically)

If SSL wasn't set up automatically, you can use Certbot:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com

Step 11: Start Ghost

If Ghost isn't already running, start it:

cd /var/www/ghost
ghost start

Accessing Your Ghost Blog

You can now access your Ghost blog at https://yourdomain.com. The admin panel is available at https://yourdomain.com/ghost.

Remember to keep your Ghost installation updated by periodically running:

cd /var/www/ghost
ghost update

Read next