How To Install Ghost on CentOS

In this short how-to I will explain how to get the Ghost publising platform up and running on CentOS 7.

First make sure CentOS is up to date

To check if you are up to date run:

sudo yum update -y

Install Node.js

Run the following commands to install Node.js from the EPEL repo:

sudo yum install -y epel-release
sudo yum install -y nodejs npm

Or if you prefer installing Node.js from source:

curl -sL https://rpm.nodesource.com/setup | bash -
sudo yum install -y nodejs
sudo npm -g install npm@latest

Download and install the latest version of Ghost

Download and unzip Ghost with the following commands:

mkdir -p /var/www/
cd /var/www/  
curl -L -O https://ghost.org/zip/ghost-latest.zip  
unzip -d ghost ghost-latest.zip  
cd ghost
sudo npm install --production

Create Ghost User

Run the following commands to add the ghost user:

sudo useradd -r ghost
sudo chown -R ghost:ghost /var/www/ghost/

Install and configure the Apache HTTP server

We are going to use Apache to proxy to port 80. Run the following commands to install the Apache HTTP server:

sudo yum install -y httpd

Create your virtual host config file /etc/httpd/conf.d/your-site.conf, add the following content and replace example.com with your domain name :

<VirtualHost *:80>
    ServerName example.com
    ProxyPreserveHost on
    ProxyPass / http://127.0.0.1:2368/
</VirtualHost>

Make Ghost start at boot

Many guides instruct to use forever or pm2. But you can also do this with systemd. Simply create the systemd service file /etc/systemd/system/ghost.service with the following content:

[Service]
ExecStart=/usr/bin/node /var/www/ghost/index.js  
Restart=always  
StandardOutput=syslog  
StandardError=syslog  
SyslogIdentifier=ghost  
User=ghost  
Group=ghost  
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target  

Now you will be able to manage Ghost via systemd:

systemctl start ghost  
systemctl stop ghost  
systemctl restart ghost  
systemctl status ghost 

Finally

Time to enable Apache and Ghost and start them. Run the following command to accomplish this:

systemctl enable ghost
systemctl enable httpd
systemctl start ghost
systemctl start httpd

And done!

Share

Uco Mesdag

A sysadmin by day and a coder by night. Working as a senior Linux system engineer with plus 20 years of experience. I write about Linux, tech, code and other things that have my interest.

You've successfully subscribed to Mesd.ag
Great! Next, complete checkout for full access to Mesd.ag
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.