How to Install Ghost on FreeBSD: A Step-by-Step Guide

How to Install Ghost on FreeBSD: A Step-by-Step Guide

Ghost is a powerful, open-source publishing platform designed for professional blogging. Known for its clean design and robust features, it's an excellent choice for anyone looking to build a personal blog or a publication. If you're using FreeBSD, you might find the installation process a bit different from other operating systems. This guide will walk you through the steps to install Ghost on FreeBSD.

Prerequisites

Before you start, ensure you have the following:

  1. A FreeBSD server with root access.
  2. A domain name pointed to your server.
  3. Basic knowledge of the command line.

Step 1: Update Your System

First, ensure your FreeBSD system is up to date. Open your terminal and run the following commands:

sudo freebsd-update fetch
sudo freebsd-update install

Then, update your package repository:

sudo pkg update
sudo pkg upgrade

Step 2: Install Node.js and npm

Ghost requires Node.js, so you'll need to install it along with npm (Node Package Manager). Run the following command:

sudo pkg install node npm

Verify the installation:

node -v
npm -v

Step 3: Install Ghost-CLI

Ghost-CLI is a command-line tool to help you install and manage Ghost. Install it globally using npm:

sudo npm install -g ghost-cli

Step 4: Create a Directory for Ghost

Create a directory where Ghost will be installed. For this guide, we'll create a directory named ghost-blog in the /usr/local/www directory:

sudo mkdir -p /usr/local/www/ghost-blog
sudo chown your_user:your_user /usr/local/www/ghost-blog
cd /usr/local/www/ghost-blog

Replace your_user with your actual username.

Step 5: Install Ghost

With the directory created and navigated into, you can now install Ghost. Run the following command:

ghost install

Follow the prompts to complete the installation. Ghost-CLI will check for any missing dependencies, install and configure MySQL, set up Nginx as a reverse proxy, and secure your site with a free SSL certificate from Let's Encrypt.

Step 6: Configure MySQL

If you don't have MySQL installed, Ghost-CLI will prompt you to install it. You can also install MySQL manually:

sudo pkg install mysql57-server
sudo sysrc mysql_enable="YES"
sudo service mysql-server start

Secure your MySQL installation:

sudo mysql_secure_installation

Create a new MySQL database and user for Ghost:

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

Replace yourpassword with a strong password.

Step 7: Configure Nginx

If Nginx is not installed, Ghost-CLI will prompt you to install it. You can also install Nginx manually:

sudo pkg install nginx
sudo sysrc nginx_enable="YES"
sudo service nginx start

Create a configuration file for your Ghost site in the /usr/local/etc/nginx/sites-available/ directory:

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

Add the following configuration, replacing your_domain.com with your actual domain:

server {
    listen 80;
    server_name your_domain.com;

    location / {
        proxy_pass http://127.0.0.1:2368;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location ~ /.well-known {
        allow all;
    }
}

Create a symbolic link to enable the configuration:

sudo ln -s /usr/local/etc/nginx/sites-available/ghost /usr/local/etc/nginx/sites-enabled/

Restart Nginx to apply the changes:

sudo service nginx restart

Step 8: Complete the Ghost Installation

Ghost-CLI will take care of the remaining steps, including setting up SSL with Let's Encrypt. Follow the prompts to complete the installation.

Conclusion

Congratulations! You've successfully installed Ghost on FreeBSD. You can now access your new blog by navigating to http://your_domain.com. From here, you can log in to the admin interface and start creating content. If you encounter any issues, refer to the Ghost documentation or the FreeBSD Handbook for additional guidance. Happy blogging!