Installing Ghost CMS on CentOS 8

Ghost is a high quality open source CMS just like WordPress. Ghost 3.0 is focused strictly on bloggers, so you can expect a more tailored experience as a blogger. Thanks to Ghost using Node.js, you can expect it to be much faster than WordPress with PHP. Ghost's interface is as clean and pretty as it gets as a CMS. The WeAreDevs blog has switched from WordPress to Ghost thanks to these benefits. If you're running a simple blog like us and want to make the switch, read this article to learn how to set up a server to run the Ghost CMS.

The assumed server stack will be CentOS 8, NGINX, MariaDB(MySQL), and Node.js.

Prerequisites

Disable Selinux

You won't be able to create your Ghost server later with Selinux enabled, so make sure you disable with with the command:

sudo setenforce 0

Note that it will turn back on after restarting your server. For a permanent solution, refer to this article.

Install the Ghost CLI

Run the command:

sudo npm install -g ghost-cli@latest

Create a non-root user

You won't be able to use the root user with the Ghost CLI , so you'll need to make another user with sudo access.

sudo adduser ghostuser

Make sure you give it a password

sudo passwd ghostuser

Give the new user sudo access

sudo usermod -aG wheel ghostuser

Set up the file tree

Navigate to where you want to install your Ghost blog

sudo mkdir -p /var/www/ghost

Give ownership of the directory to your non-root user

sudo chown ghostuser:ghostuser /var/www/ghost

Adjust the directory's read/write permissions

sudo chmod 775 /var/www/ghost

Navigate to the directory

cd /var/www/ghost

Be sure that the directory is empty of any kind of file. To clear a directory, run the command:

sudo rm -rf ./*

Switch to your non-root user. Ghost doesn't allow you to install their CMS as the root user.

sudo su - ghostuser

Switching users cds you into the user's home directory. You will need to cd back into your desired website directory.

cd /var/www/ghost

Install Ghost using production mode settings

ghost install
  1. You will first be prompted with a warning stating you aren't on Ubuntu. Just ignore it and enter "y" to continue.
  2. You will be prompted with another warning stating that the MySQL setup will be skipped. Ignore this and enter "y" to continue.
  3. You will be asked for your blog URL. Enter whatever your domain will be for your blog. ex. myblog.mydomain.com.
  4. When your MySQL hostname will be requested. Enter localhost.
  5. You MySQL username and password will be requested. Enter it as you defined when installing MariaDB. Your username is probably root if you didn't make a another user.
  6. When it asks if you want to setup a "ghost" MySQL user, enter no. Unless you want one... It's up to you. Be confident of your security decision if you allow remote connections to the database or plan on modifying the Ghost source.
  7. When it asks to configure "Systemd", enter "y".
  8. When it asks to start Ghost, enter "y"

Configuring NGINX to proxy requests

Your Ghost blog should be running by now, but it is not yet accessible on the web. We need to use NGINX to proxy requests to the Ghost server.

Determine and remember your Ghost server's port. You can see it in the output from the following command:

ghost ls

Switch back to your root user

sudo su -

Install the nano text editor

sudo yum install nano

Create an NGINX configuration file for your Ghost blog

nano /etc/nginx/conf.d/ghostblog.conf

Paste in the following content and edit it appropriately. Be sure to correct the domain and port number.

#default_server
server {
    listen 80;
    listen [::]:80;
    #Replace your domain
    server_name blog.mydomain.com;

    #Proxy to ghost
    location / {
        #Replace the port number here
        proxy_pass http://localhost:2368;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Be aware that the configuration above is minimal. You'll want to apply your usual additional configuration like rate limiting and such to prevent DDoS attacks.

Restart/reload NGINX to update the configuration.

sudo service restart nginx

Your Ghost blog is now ready to visit. Navigate to your assigned blog's domain and you will see the basic CMS setup. Hopefully you can handle the rest from here.

Note: Everytime you restart your Ghost blog server, you may need to update the port number in your NGINX configuration.